Data Structures & AlgorithmsModerateTCS NQT Digital · Accenture
Problem: The string "aaaaa" is split into non-overlapping occurrences of "aa" from left to right (greedily taking each match). How many occurrences are found?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Non-overlapping greedy matching jumps past each match, so five letters give two matches with one letter left over. Overlapping search would find four.
More Coding Interview Problems questions
- 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?
- Problem: What is the length of the longest common subsequence of the three strings "abc", "abd" and "ab"?