Data Structures & AlgorithmsVery hardAmazon/Microsoft SDE pattern
Using a sliding window of fixed size with a character-frequency count, how many substrings of "BAAAABBAACB" are anagrams of "AB"?
- A. 1
- B. 4
- C. 2
- D. 3
Correct answer: D. 3
A window of length 2 is an anagram of "AB" exactly when their character-frequency counts match, not when the characters appear in the same order. Checking every window of "BAAAABBAACB" this way gives 3 matches, versus only 1 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
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- A queue is implemented with two stacks (enqueue pushes to stack "in"; dequeue pops from stack "out", refilling "out" from "in" by…
- Floyd's cycle detection runs on a linked list 1 → 2 → ... → 8 whose last node's next pointer points back to node 4 (0-based position 3)…
- Array [36, 53, 71, 81, 12, 18, 20, 26] is a sorted array rotated at pivot 4. Using the standard O(log n) rotated-array binary search…
- Binary search for first/last occurrence runs on the sorted array [2, 7, 9, 11, 16, 16, 17, 18] for target 16. What (first index, last…
- A recursive function is defined as f(0) = f(1) = 1 and f(n) = f(n−1) + 2·f(n−2) for n ≥ 2. Using memoization, what is f(6)?