Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Strings "axbycz" and "abc" are given. Count the subsequences of "axbycz" that equal "abc" (indices must be increasing, and different index sets count separately).
- A. 1
- B. 2
- C. 0
- D. 3
Correct answer: A. 1
Subsequence counting uses a DP over pattern prefixes, updated from the longest prefix downward. Here each letter of abc appears exactly once, so the count equals the number of ways to pick one index per letter.
More Coding Interview Problems questions
- Problem: Starting with the list [1, 2, 3, 4, 5, 6], repeatedly remove every second element (keeping the first) until one element remains…
- Problem: In the array [5, 1, 4, 2, 8, 0, 2], count the pairs (i, j) with i < j and a[i] > 2·a[j] (so a[i] is more than double a[j]).
- Problem: The string "aabcbbca" is processed by a sliding window that keeps at most one distinct letter 'a' inside (other letters are…
- Problem: How many integers in [1, 200] are divisible by exactly one of 6 and 8?
- Problem: The Euler's criterion test: count the quadratic residues modulo 13 among 1 through 12 (a residue r satisfies x² ≡ r for some…
- Problem: How many 4-digit numbers (1000 to 9999) have all four digits distinct and in strictly decreasing order from left to right?