Data Structures & AlgorithmsModerateGATE CS · TCS NQT
What is the length of the longest NON-DECREASING subsequence (equal neighbours allowed) of [5, 1, 3, 3, 2, 6, 6, 4, 7]?
- A. 4
- B. 9
- C. 6
- D. 3
Correct answer: C. 6
Patience sorting with bisect_right lets equal values extend a chain: 1, 3, 3, 6, 6, 7 has length 6. bisect_left forbids equal values and gives the strict LIS 4, 9 is the array length and 3 is the longest non-decreasing contiguous run.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many subsets of [2, 3, 5, 4, 6] (chosen by position) have a sum exactly equal to half of the total sum?
- A staircase has 8 steps. Each move climbs 1 or 2 steps, but you may NOT take three single-step moves in a row. How many different…
- In the binary array [1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1] you may flip at most 2 zeros to ones. What is the length of the longest run of…
- Positions 0 to 9 form a line. Cells marked 1 are blocked, the rest are free. From a cell you may jump forward by at most 3 positions (to…
- Positions [15, 3, 22, 9, 40, 27] are given in arbitrary order. What is the largest difference between two consecutive positions when the…
- How many subsets (chosen by position, the empty subset included) of [6, 1, 3, 5, 2] have a bitwise XOR equal to 4?