Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 B
What is the length of the longest substring of abcabdabcd that contains at most two distinct characters?
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
A sliding window with a count map finds the longest stretch containing at most two letters. Restarting the window at each new letter is incorrect.
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 pairs of distinct positions (i, j) with i < j in the string abcdcba satisfy s[i] = s[j]?
- In the sequence of queue operations enqueue 5, enqueue 3, dequeue, enqueue 8, dequeue, dequeue, enqueue 1, what is the value at the front…
- For the pattern "aabaabaaab" (0-based), what is the value of the KMP prefix function π at the LAST index? π[i] is the length of the…
- How many times does the pattern "aaa" occur in the text "aaaabaaaaab", counting OVERLAPPING occurrences (occurrences may share letters)?
- Using the Z-function (z[i] = length of the longest common prefix of s and s[i..], with z[0] = n), what is the sum of all z-values of…
- What is the length of the longest substring of "pwwkewfabcdbbca" with no repeated character?