Count Ways to Build a Target from Increasing Dictionary Columns
Company: Visa
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Online Assessment
Overview: Count target-string constructions by combining per-column character frequencies with prefix dynamic programming. Explain increasing-column constraints, descending updates, multiplicity, and modular arithmetic for larger inputs.
Constraints
- words is nonempty, all words have the same nonzero length, and every character in words and target is lowercase English a through z.
- target is nonempty; exact enlarged interview input-size bounds were not reported.
- Columns chosen for successive target characters must be strictly increasing.
- Different word indices are distinct choices, including identical word strings.
- Return the count modulo 1000000007.
Examples
Input: (['aa', 'ab'], 'aa')
Expected Output: 2
Explanation: Two choices for the first a at column zero and one at column one.
Input: (['a'], 'a')
Expected Output: 1
Explanation: The only matching cell is one choice.
Hints
- A column can contribute several choices for one target character.
- A target longer than every word cannot use enough increasing columns.