Data Structures & AlgorithmsVery hardGATE CS · TCS NQT
What is the length of the longest substring of "aaabbbcaabbbcc" in which every letter occurring in it appears at least 3 times?
- A. 15
- B. 14
- C. 13
- D. 6
Correct answer: B. 14
The whole string qualifies, since a, b and c each occur at least 3 times, so no split is needed. Splitting at letters with fewer than k occurrences is the general method.
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 contiguous subarrays of [1, 2, 3, 3, 2, 1, 4] have a bitwise XOR of exactly 0?
- Among pairs of distinct elements of [-8, -3, 1, 5, 9, 12], which pair sum is closest to the target 4? (Report the sum itself.)
- What is the sum of the minimum element over all contiguous subarrays of [5, 3, 1, 4, 2]?
- What is the area of the largest rectangle containing only 1s in the binary matrix whose rows are 1101, 1111, 0111 and 1110?
- A grid has rows ..#. / .##. / .... / #.#. where '.' is free and '#' is a wall. Moving up, down, left or right one cell at a time, what is…
- Two sorted linked lists A = [1, 4, 6, 9] and B = [2, 3, 7, 10, 12] are merged with the standard two-pointer merge, which compares the…