Data Structures & AlgorithmsVery hardProduct-company MCQ pattern
Using a sliding window of fixed size with a character-frequency count, how many substrings of "CBCAACACBABCB" are anagrams of "CAB"?
- A. 3
- B. 5
- C. 4
- D. 0
Correct answer: C. 4
A window of length 3 is an anagram of "CAB" exactly when their character-frequency counts match, not when the characters appear in the same order. Checking every window of "CBCAACACBABCB" this way gives 4 matches, versus only 0 if exact substring equality (same order) were required instead.
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
- The Boyer–Moore majority vote algorithm (candidate/counter, no verification pass) runs on [1, 3, 3, 1, 1, 3, 3, 3]. What candidate and…
- Array [90, 6, 26, 27, 39, 47, 79] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary search (decide…
- Two sorted linked lists [12 → 17 → 24 → 26 → 32] and [8 → 10 → 12 → 38] are merged with the standard O(n+m) two-pointer merge (always take…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [1, 1, 2, 2, 1, 1, 1, 1, 2, 0] (values 0, 1, 2…
- Heights [8, 6, 3, 2, 6, 8, 8, 4, 7, 1] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal…
- Kadane's algorithm runs on the array [5, 4, 4, -3, -5, -1, 8] to find the maximum sum of a contiguous subarray. What sum does it return?