As reported: Coupang L5 Senior Software Engineer loop, Bangalore (2025), round 1 (DSA): given a source pattern and a target string, count how many ways the pattern can be obtained from the target as a subsequence, where consecutive characters of the target may not be chosen. A working solution was expected; DFS with memoisation solves it.
Given strings pattern and target, count the ways to choose indices i1 < i2 < … < ik in target (k = |pattern|) such that target[i1] target[i2] … target[ik] spells pattern, and no two chosen indices are adjacent (i(j+1) − i(j) ≥ 2).
Return the count modulo 10^9 + 7.
Example 1
pattern = "abc", target = "abbccc" -> 2
a must be index 0, so b can only be index 2 (index 1 is adjacent). c must then be at index 4 or 5 (index 3 is adjacent to 2): two ways.
Example 2
pattern = "aa", target = "aaaa" -> 3
Index pairs (0,2), (0,3), (1,3).
Example 3
pattern = "ab", target = "ab" -> 0
Constraints: 1 ≤ |pattern| ≤ 100; |pattern| ≤ |target| ≤ 1000; both consist of lowercase English letters.
Code runner format: two lines — pattern, then target (JSON strings). Implement countWays(pattern, target); the harness prints the count.