Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: The string "cbaebabacd" is scanned with windows of length 3. How many windows are anagrams of "abc" (same letters, same counts, any order)?
- A. 3
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
Each window is an anagram exactly when its letter counts match the pattern's counts. Checking whether the window contains each letter once is the same test here, but counting distinct letters alone is insufficient in general.
More Coding Interview Problems questions
- Problem: The string "aaaaa" is split into non-overlapping occurrences of "aa" from left to right (greedily taking each match). How many…
- Problem: In the string "aabcbcdbca", what is the length of the shortest substring that contains exactly 3 distinct letters?
- Problem: What is the length of the longest palindromic substring of "abcbxa" that can be made a palindrome after deleting at most one…
- Problem: How many sequences made of the numbers 1 and 2 sum to 8, where no two 2s are adjacent (order matters)?
- Problem: From the array [−10, −10, 5, 2], pick three numbers (distinct positions) to maximise their product. What is the maximum product?
- Problem: The edit distance (insert, delete, replace, each cost 1) between "horse" and "ros" is computed. What is it?