Number of Ways to Form a Target String Given a Dictionary
A hard-tier problem at 57% community acceptance, tagged with Array, String, Dynamic Programming. Reported in interviews at Dunzo and 3 others.
You're given a dictionary of words and need to count how many ways you can form a target string by picking one character at a time from each word in the dictionary, always moving left to right through both. Dunzo, Snowflake, Meesho, and Snap have all asked this. It's a hard DP problem with a 57% acceptance rate, which means roughly half the candidates who attempt it fail. The trick isn't obvious on first read. Most people overthink the state space or miss the independence property between characters.
Companies that ask "Number of Ways to Form a Target String Given a Dictionary"
Number of Ways to Form a Target String Given a Dictionary is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe problem is a 2D DP challenge where you track two positions: where you are in the target string and which word you're currently examining. The critical insight is that for each character in the target, you can pick it from any word at any column, and that choice is independent of previous picks. Many candidates build a DP table checking both positions (target index and word index), but they miss how to avoid redundant states or how to compress the second dimension. The pattern requires careful indexing: count ways to form target[0:i] using only the first j words. If you code this naively, you'll hit TLE. If you don't recognize this is a combination problem at heart (how many columns give you the character you need), you'll get stuck debugging transitions. StealthCoder surfaces the working state logic and transition in seconds if you blank on it live.
Pattern tags
You know the problem.
Make sure you actually pass it.
Number of Ways to Form a Target String Given a Dictionary recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Number of Ways to Form a Target String Given a Dictionary interview FAQ
Is this really a hard problem, or is it just advertised that way?+
The 57% acceptance rate suggests it's legitimately hard. It combines string matching with DP state design. The trick isn't algorithmic heavy-lifting; it's recognizing that character picks are independent and building the right DP table structure. Many candidates get the idea but fail on indexing or optimization.
What's the most common way people get stuck on this?+
They either treat it like a longest common subsequence problem (which it isn't) or they don't realize you can pick the same word multiple times. The second mistake is catching a character from word 3 for target[2], then word 1 for target[3]. Once you see that pattern, the DP click happens faster.
Does this really need dynamic programming, or can I brute force it?+
Brute force kills you on time. A greedy or naive recursive approach explodes exponentially. DP reduces it to polynomial time by memoizing which (target position, word index) states you've seen. Without memoization, you time out.
How does the Array and String classification fit this problem?+
The dictionary is an array of words (strings). You iterate the dictionary once, and for each word, you iterate its characters. The target is a string you build up one character at a time. All three topics converge: you're combining data structures (array), text matching (string), and state management (DP).
If I see this problem live in an OA and I've never drilled it, what's my move?+
Write out a small example on paper first: what does the DP table actually store, and how does each cell depend on the last. If that doesn't click in 5 minutes, you're chasing a wrong model. StealthCoder runs invisibly during screen share and gives you a working solution so you don't tank the assessment on pattern recognition.
Want the actual problem statement? View "Number of Ways to Form a Target String Given a Dictionary" on LeetCode →