Data Structures & AlgorithmsHardProduct-company MCQ pattern
Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the longest substring of "BCABBDDDACBBD" containing at most k = 3 distinct characters?
- A. 6
- B. 13
- C. 5
- D. 7
Correct answer: D. 7
Sliding the window right and shrinking from the left whenever the distinct-character count exceeds k = 3 gives a longest valid window of length 7. Using k = 2 would give 5, and using k = 4 would give 13 — off-by-one errors on the distinct-count bound.
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
- Elevation map [4, 5, 4, 4, 0, 1, 2, 1, 0, 2] (bar width 1). Using the two-pointer / prefix-max approach for trapping rain water, how much…
- A circular queue of capacity 4 starts empty and runs this sequence in order: enqueue(3), enqueue(6), enqueue(4), enqueue(7), dequeue()…
- The Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [7, 5, 2, 5, 5, 5, 2, 7]. What candidate and…
- What does this loop-counting code print? (Python) python n, c = 45, 0 i = 1 while i < n: j = i while j < n: c += 1 j = 2 i += 1 print(c)
- Array [83, 87, 90, 43, 45, 48, 62, 75, 82] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary search…
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "AAABAAABCB" are anagrams of "BA"?