Data Structures & AlgorithmsHard
What is the length of the longest contiguous substring of "aabbccabcdd" in which EVERY distinct letter appears at least twice?
- A. 2
- B. 12
- C. 11
- D. 10
Correct answer: C. 11
Every letter in the window must occur at least twice, which a window with a count map checks as it grows. Requiring only one copy, looking only at runs of the same letter, or adding one to the answer each give other values.
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 windows of length exactly 5 in 1 2 3 4 5 6 7 8 9 10 2 have a PRIME sum?
- How many contiguous subarrays of 2 4 6 4 2 8 have an AVERAGE exactly equal to the average of the whole array?
- For 3 9 1 7 2 8 4, split the array into a non-empty left part and a non-empty right part at some position p. What is the LARGEST possible…
- Using only swaps of ADJACENT characters, what is the minimum number of swaps needed to move ALL letters 'x' of "bxaxxbx" to the very front…
- From the digit string "53412", delete EXACTLY two characters (the remaining characters keep their order). What is the lexicographically…
- How many DISTINCT non-empty strings can be formed as subsequences (characters taken in order, not necessarily adjacent) of "abab"?