Data Structures & AlgorithmsVery hardTCS NQT · Infosys pattern
Using a sliding window of fixed size with a character-frequency count, how many substrings of "BABAAABCC" are anagrams of "AB"?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: B. 4
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 "BABAAABCC" this way gives 4 matches, versus only 2 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 Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [0, 2, 2, 2, 1, 1, 2, 2, 0, 1] (values 0, 1, 2…
- 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(10)?
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- Elevation map [3, 4, 1, 3, 4, 6, 3, 5, 4] (bar width 1). Using the two-pointer / prefix-max approach for trapping rain water, how much…
- Heights [9, 2, 9, 6, 1, 6, 3] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal distance)…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [2, 1, 0, 2, 2, 0, 1, 2, 2] (values 0, 1, 2 only)…