Data Structures & AlgorithmsHardProduct Company SDE · Amazon/Microsoft-style OA
Problem: How many windows of length 3 in the text "bacacbaab" are anagrams of the pattern "aab" (same letters with the same multiplicities, any order)?
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
Sliding-window multiset comparison: a window is an anagram iff its letter counts equal the pattern's counts. Checking only that the window contains the same set of letters ignores multiplicities.
More Coding Interview Problems questions
- Problem: What is the length of the longest substring of "eceebaabbccbdeeabe" that contains at most 2 distinct characters?
- Problem: Find the lexicographically smallest rotation of the string "dcbadcb". What is its starting index (0-based) in the original…
- Problem: The longest common subsequence of "ABCBDAB" and "BDCABA" has length L. What is L?
- Problem: From the string "aaabbbaabbccaa", you may delete the minimum number of characters so that no two adjacent characters are equal…
- Problem: A stack-based reduction processes the string "abbaca" from left to right: if the current character equals the top of the stack…
- Problem: Bubble sort is run on [5, 2, 9, 1, 7, 3, 8, 6, 4] using the standard adjacent-swap pass (for i from 0 to n−2, swap a[j] and…