- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 10784 Articles for Python
290 Views
Suppose we have a list of sorted list of distinct integers of size n, we have to find the first positive number in range [1 to n+1] that is not present in the array.So, if the input is like nums = [0, 5, 1], then the output will be 2, as 2 is the first missing number in range 1 to 5.To solve this, we will follow these steps −target := 1for each i in arr, doif i is same as target, thentarget := target + 1return targetLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More
128 Views
Suppose we have a list of numbers called nums, we have to find the first missing positive number. In other words, the lowest positive number that does not present in the array. The array can contain duplicates and negative numbers as well.So, if the input is like nums = [0, 3, 1], then the output will be 2To solve this, we will follow these steps −nums := a set with all positive numbers present in numsif nums is null, thenreturn 1for i in range 1 to size of nums + 2, doif i is not present in nums, thenreturn iLet ... Read More
288 Views
Suppose we have given a list of numbers called ratings, and this is showing the performance scores of coders. Now the manager wants to give Rs 1000 to every coder except if two coders are adjacent, they would like to pay the better performing coder at least Rs 1000 higher than the worse performing one. We have to find the minimum amount the manager can pay following above constraints.So, if the input is like ratings = [1, 2, 5, 1], then the output will be 7000, as the minimum we can pay for each respective coder is [1000, 2000, 3000, ... Read More
160 Views
Suppose we have a positive number n, we have to check whether n can be written as the sum of unique positive factorial numbers or not.So, if the input is like n = 144, then the output will be True, as 4! + 5! = 24 + 120 = 144To solve this, we will follow these steps −fact := 1res := a new listx := 2while fact = res[i], thenn := n - res[i]return true when n is same as 0Let us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, n): fact = 1 ... Read More
160 Views
Suppose we have a list of sorted numbers called nums, we have to find the sum of the absolute differences between every pair of numbers in the given list. Here we will consider (i, j) and (j, i) are different pairs. If the answer is very large, mod the result by 10^9+7.So, if the input is like nums = [2, 4, 8], then the output will be 24, as |2 - 4| + |2 - 8| + |4 - 2| + |4 - 8| + |8 - 2| + |8 - 4|.To solve this, we will follow these steps −m ... Read More
331 Views
Suppose we have a robot, that is currently sitting in at position (0, 0) (Cartesian plane). If we have list of its moves that it can make, containing N(North), S(South), W(West), and E(East). We have to check whether it can reach at destination coordinate (x, y).So, if the input is like moves = ['N', 'N', 'E', 'E', 'S'], (x, y) = (2, 1), then the output will be True, To solve this, we will follow these steps −temp_coord := [0, 0]for each move in moves, doif move is same as "N", thentemp_coord[1] := temp_coord[1] + 1otherwise when move is same ... Read More
293 Views
Suppose we have a string containing letters of three types, R, B, and dot(.). Here R stands for our current position, B stands for a blocked position, and dot(.) stands for an empty position. Now, in one step, we can move to any adjacent position to our current position, as long as it is valid (empty). We have to check whether we can reach either the leftmost position or the rightmost position.So, if the input is like s = "...........R.....BBBB.....", then the output will be True, as R can reach left most position, because there is no block.To solve this, ... Read More
146 Views
Suppose we have some parameters P, O, E, T. If we have P dollars in principal that we want to invest the stock market. The stock market alternates between first returning E and then O percent interest per year, we have to check how many years it would take to reach at least T dollars.So, if the input is like P = 200, O = 10, E = 25, T = 300, then the output will be 3 as in the first year we will get interest 25%, so end up with 200+50 = 250, then next year we will ... Read More
434 Views
Suppose we have a string of words delimited by spaces; we have to reverse the order of words.So, if the input is like "Hello world, I love python programming", then the output will be "programming python love I world, Hello"To solve this, we will follow these steps −temp := make a list of words by splitting s using blank spacetemp := reverse the list tempreturn a string by joining the elements from temp using space delimiter.Let us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, s): temp = s.split(' ') ... Read More
148 Views
Suppose we have two lists of numbers called A, and B. We have to take some sublist in A and reverse it. Then check whether it is possible to turn A into B or not. We can take sublist and reverse it any number of times.So, if the input is like A = [2, 3, 4, 9, 10], B = [4, 3, 2, 10, 9], then the output will be True as we can reverse [2, 3, 4] and [9, 10].To solve this, we will follow these steps −res := a map, initially emptyfor each n in nums, dores[n] := ... Read More