
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

484 Views
Suppose we have a list of numbers called nums, we have to find the size of the longest subsequence where the difference between two consecutive numbers alternate between positive and negative. And the first difference may be either positive or negative.So, if the input is like nums = [6, 10, 4, 2, 3, 9, 4, 7], then the output will be 6, as on possible required subsequence is [6, 10, 2, 9, 4, 7] and the differences are [4, -8, 7, -5, 3].To solve this, we will follow these steps &minuS;n := size of numsdp := a list of size ... Read More

386 Views
Suppose we have a list of numbers called nums and that is sorted in non-decreasing order, we have to check whether it can be split into any number of subsequences such that each subsequence has at minimum length of 3 and that is consecutively increasing.So, if the input is like nums = [2, 3, 4, 4, 5, 6, 7], then the output will be True, as we can split the list to [2, 3, 4] and [4, 5, 6, 7].To solve this, we will follow these steps −counts := A map that contains elements of nums and its countsstarts := ... Read More

192 Views
Suppose we have a list of numbers called nums, and another value k, we have to check whether it is possible to split the list into sublists lists such that each sublist has length ≥ k and that is strictly increasing. The list does not need to be split contiguously.So, if the input is like nums = [6, 7, 5, 10, 13] k = 2, then the output will be True, as the split is [5, 6] and [7, 10, 13].To solve this, we will follow these steps −c := A map that contains elements of nums and its countsmax_count := maximum of all frequencies of creturn True when max_count * k

155 Views
Suppose we have a list of numbers called nums and another value k, we have to find the largest sum of three non-overlapping sublists of the given list of size k.So, if the input is like nums = [2, 2, 2, -6, 4, 4, 4, -8, 3, 3, 3] k = 3, then the output will be 27, as we can select the sublists [2, 2, 2], [4, 4, 4], and [3, 3, 3], total sum is 27.To solve this, we will follow these steps −P := [0]for each x in A, doinsert P[-1] + x at the end of ... Read More

160 Views
Suppose we have a binary tree, we have to find the largest subtree (with maximum number of nodes) as binary search tree.So, if the input is likethen the output will beTo solve this, we will follow these steps −max_size := [0]max_node := [null]Define a function traverse() . This will take nodeif node is null, thenreturn nullleft := traverse(left of node)right := traverse(right of node)lst := left + [value of node] + rightif lst is sorted, thenif max_size[0] < size of lst, thenmax_size[0] := size of lstmax_node[0] := nodereturn lsttraverse(root)From the main method return max_node[0]Example (Python)Let us see the following implementation ... Read More

391 Views
Suppose we have one N x M binary matrix. Where 0 means empty cell and 1 means blocked cell. Now starting from the top left corner, we have to find the number of ways to reach the bottom right corner. If the answer is very large, mod it by 10^9 + 7.So, if the input is like001000110then the output will be 2, as There are two ways to get to the bottom right: [Right, Down, Right, Down] and [Down, Right, Right, Down].To solve this, we will follow these steps −dp := a matrix of same size of given matrix and ... Read More

193 Views
Suppose we have a list of numbers called nums and another value k, we have to find the number of sublists required that there are exactly k unique numbers in the sublist.So, if the input is like nums = [2, 2, 3, 4] k = 2, then the output will be 3, as we have the sublists like: [2, 2, 3], [2, 3], [3, 4].To solve this, we will follow these steps −Define a function count() . This will take Kslot := an empty map, by default all values are 0i := res := 0for each index j, and value ... Read More

334 Views
Suppose we have a list of numbers called nums and another value k, we have to find the lexicographically smallest subsequence of size k.So, if the input is like nums = [2, 3, 1, 10, 3, 4] k = 3, then the output will be [1, 3, 4]To solve this, we will follow these steps −l := size of nums, r := k - 1out := a new listfor j in range 0 to k, domn := nums[complement of r]for i in range r to l, doif mn >= nums[complement of i], thenmn := nums[complement of i]l := ir := ... Read More

829 Views
Suppose we have a list of intervals where each interval contains three values [start, end, profit]. We can perform only one task at a time, we have to find the most amount of profit we can get.So, if the input is like intervals = [[1, 2, 100], [3, 5, 40], [6, 19, 150], [2, 100, 250]], then the output will be 350, as we can take these two intervals [1, 2, 100] and [2, 100, 250]To solve this, we will follow these stepsd := an empty map that contains lists as valuesn := 0for each (start, end, profit) in intervals, ... Read More

482 Views
Suppose we have a list of numbers called nums and also another value k, we have to find the number of subsequences of size k that are strictly increasing. If the answer is very large, mod it by 10^9 + 7.So, if the input is like nums = [2, 3, 4, 1] k = 2, then the output will be 3, as we have the subsequences of size 2: [2, 3], [3, 4], [2, 4].To solve this, we will follow these steps −m := 10^9 + 7dp := a list of size same as nums and fill with 1iterate the ... Read More