Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Consider the routine that computes the length of the longest STRICTLY increasing subsequence of [2, 2, 3, 3, 4, 4, 5] using the tails array with bisect_right instead of bisect_left. What does it return, compared with the correct strict LIS length?
- A. 4
- B. 7
- C. 6
- D. 8
Correct answer: B. 7
bisect_right places an equal value after the existing equal tail, extending the chain across duplicates. The bug therefore counts a non-strict increase, and the answer exceeds the strict LIS.
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 unordered pairs of positions of the same letter are there in "abracadabra" (i < j with s[i] = s[j])?
- A Java program computes d[0] = d[1] = 1 and d[i] = d[i−1] + d[i−2] using int (32-bit two's complement, wrapping on overflow) with no…
- What is the largest sum of any contiguous window of exactly 4 elements of [2, 7, 1, 8, 2, 8, 1, 8, 2, 8]?
- How many non-empty subsets of [3, 5, 6, 7, 9] (chosen by position) have a sum divisible by 4?
- A row of 100 lights starts off. For each i from 1 to 100, the lights at positions that are multiples of i are toggled. How many lights are…
- The array [1, 9, 4, 6, 2, 8] has even length. You pair up the elements (each element in exactly one pair), and the cost of the arrangement…