
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

227 Views
Suppose we have a list of numbers called nums. We have to find the minimum positive value that we can insert at the beginning of nums so that that prefix sums of the resulting list contains numbers that are all larger than 0.So, if the input is like nums = [3, -6, 4, 3], then the output will be 4, because if we insert 4 to the list then we have [4, 3, -6, 4, 3]. Now the prefix sums are then [4, 7, 1, 5, 8], all are larger than 0.To solve this, we will follow these steps −insert ... Read More

2K+ Views
Suppose we have three strings text, w1, and w2. The text is a sentence with different words. We have to find the smallest distance between any two occurrences of w1 and w2 in the text, the distance is measured in number of words in between them. If either w1 or w2 is not present in text, return -1.So, if the input is like text = "joy happy power happy joy joy power happy limit" w1 = "power" w2 = "limit", then the output will be 1, as there is only one word "happy" in between the power and limit.To solve ... Read More

495 Views
Suppose we have a lit of numbers called nums, and have another value k. If we remove k elements from nums, then find the minimum of (maximum of nums - minimum of nums).So, if the input is like nums = [4, 10, 3, 2, 8, 9] k = 3, then the output will be 2, because if we remove 10, 8 and 9 then maximum is 4, minimum is 2 so difference is 2.To solve this, we will follow these steps −sort the list numsp := size of nums - km := (last element of nums) - nums[0]for i in ... Read More

289 Views
Suppose we have a list of numbers called nums and a value k. First we shall remove a sublist of size k, then find the minimum of (maximum of nums - minimum of nums).So, if the input is like nums = [2, 3, 10, 9, 8, 4] k = 3, then the output will be 2, If we remove [10, 9, 8] we get [2, 3, 4] and 4 - 2 = 2To solve this, we will follow these steps −N := size of numscopy nums into lmin and lmaxalso copy nums into rmin and rmaxfor i in range 1 ... Read More

131 Views
Suppose we have a number n, we have to find the maximum number we can get by inserting 5 anywhere in the number.So, if the input is like n = 834, then the output will be 8534.To solve this, we will follow these steps −if n > 0, thens := n as stringk := blank stringc := Falsefor each character i in s, doif i < 5 and c is False, thenk := k concatenate "5" concatenate ic := Trueotherwise, k := k concatenate ireturn k as integerotherwise, k := blank strings := |n| as stringc := Falsefor each character ... Read More

1K+ Views
Suppose we have a list of numbers called nums, we have to find the largest product of two unique elements.So, if the input is like nums = [8, -3, 1, -5], then the output will be 15, (-3)*(-5) = 15 which is maximum here.To solve this, we will follow these steps −n := size of numsnums_sort := sort the list numsmax_left := nums_sort[0] * nums_sort[1]max_right := nums_sort[n-1] * nums_sort[n-2]ans := maximum of max_left and max_rightreturn ansExampleLet us see the following implementation to get better understandingdef solve(nums): nums_sort = sorted(nums) max_left = nums_sort[0] * nums_sort[1] max_right = nums_sort[-1] ... Read More

384 Views
Suppose we have a list of numbers called nums, we have to find the largest product of three unique elements.So, if the input is like nums = [6, 1, 2, 4, -3, -4], then the output will be 72, as we can multiply (- 3) * (-4) * 6 = 72.To solve this, we will follow these steps −sort the list numsn := size of numsmaxScore := -infmaxScore := maximum of maxScore and (nums[0] * nums[1] * nums[n - 1])maxScore := maximum of maxScore and (nums[n - 3] * nums[n - 2] * nums[n - 1])return maxScoreExampleLet us see the ... Read More

336 Views
Suppose we have two lists called nums and multipliers. Now consider an operation where we can remove any number from nums and remove any number from multipliers then multiply them together. We must repeat this operation until one of the lists is empty, we have to find the maximum sum of the multiplied numbers.So, if the input is like nums = [-4, 4, 3] multipliers = [-2, 2], then the output will be 16, as We can match -4 with -2 and 4 with 2 to get -4 * -2 + 4 * 2.To solve this, we will follow these ... Read More

526 Views
Suppose we have a list with only 0s and 1s called seats. Where seats[i] represents a seat. When it is 1, then it is occupied, otherwise free. There is at least one free seat and at least one occupied seat, we have to find the maximum distance from a free seat to the nearest occupied seat.So, if the input is like seats = [1, 0, 1, 0, 0, 0, 1], then the output will be 2, because we can occupy seat seats[4], then distance is 2.To solve this, we will follow these steps −res := 0last := -1n := size ... Read More

325 Views
Suppose we have n different nodes. All are distinct. We have to find how many number of ways we can arrange them to form Binary search tree. As we know for binary search trees, the left subtree always hold smaller values and right subtrees hold the greater values.To solve this, we shall find the Catalan number. The Catalan number C(n) represents the binary search trees with n different keys. The formula is like$$C(n)=\frac{(2n)!}{(n+1)!\times n!}$$So, if the input is like n = 3, then the output will be 5 becauseTo solve this, we will follow these steps −Define a function ncr() ... Read More