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]?

  1. A. 4
  2. B. 9
  3. C. 6
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic