Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: How many distinct two-letter substrings does "mississippi" contain?
- A. 10
- B. 4
- C. 16
- D. 7
Correct answer: D. 7
Slide a window of 2 and keep a set: mi, is, ss, si, ip, pp, pi → 7. Counting all 10 window positions double-counts is, ss, si, 4 is the number of distinct letters, and 16 counts every possible ordered pair of those letters.
More Coding Interview Problems questions
- Problem: The smallest period of a string s is the least p ≥ 1 such that s[i] = s[i+p] for all valid i. What is the smallest period of…
- Problem: What is the length of the longest proper border (a proper prefix that is also a suffix) of "abacabacaba"? A proper border is…
- Problem: How many runs (maximal blocks of equal consecutive characters) does "aabbbaaaacc" contain?
- Problem: Houses are arranged in a circle with values [2, 3, 2, 5, 1]. You may rob any set of houses with no two adjacent in the circle…
- Problem: Count the subsets of [3, 1, 4, 2, 6, 4] whose sum is exactly half the total sum (the subset may be any size; the empty subset is…
- Problem: Count the longest increasing subsequences (subsequences of maximum length, strictly increasing) of [1, 3, 5, 4, 7]. Two index…