Interleaving String
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reportedly served Interleaving String in September 2026, and the constraints are the tell. Both sources run up to 100 characters, so trying every way to split s3 between them means up to 2^200 paths. Brute force dies fast. This is a string DP problem dressed up as a recursion puzzle, and once you see the grid, it's about ten lines. If you blank during the real OA, StealthCoder runs invisibly on your desktop and hands you the solution as a safety net. But the pattern is learnable tonight.
The problem
Given strings s1, s2, and s3, return whether s3 can be formed by interleaving s1 and s2. An interleaving uses every character from both source strings exactly once while preserving the left-to-right order within each source. Characters chosen from the two sources may alternate in groups of any positive length. Function isInterleave(s1: String, s2: String, s3: String) → boolean Examples Example 1 s1 = "aabcc" s2 = "dbbca" s3 = "aadbbcbcac" return = true The target can choose characters from both source strings while retaining each source's internal order. Example 2 s1 = "aabcc" s2 = "dbbca" s3 = "aadbbbaccc" return = false Every possible choice eventually needs to reverse or skip a character from one source, so the target is not an interleaving. Example 3 s1 = "" s2 = "" s3 = "" return = true The empty target uses every character from both empty source strings. Constraints 0 <= s1.length, s2.length <= 100. 0 <= s3.length <= 200. All three strings contain only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: define dp[i][j] as true if the first i characters of s1 and the first j characters of s2 can interleave into the first i+j characters of s3. Transition: dp[i][j] is true if (dp[i-1][j] and s1[i-1] == s3[i+j-1]) or (dp[i][j-1] and s2[j-1] == s3[i+j-1]). Base case dp[0][0] is true. Check first that len(s1)+len(s2) == len(s3), otherwise return false immediately. That's the pitfall people miss. Greedy matching fails because when both sources match the current character, you can't know which to pick. You can compress to a single row since each cell only needs the cell above and the cell to the left. That gives O(m*n) time and O(n) space. If the grid logic slips under pressure, StealthCoder is the hedge on the live OA.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Interleaving String cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as interleaving string. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Interleaving String FAQ
What's the trick to Interleaving String?+
Use a 2D DP table where dp[i][j] means s1's first i chars and s2's first j chars can form s3's first i+j chars. Each cell checks whether the last char of s3 matches the last char of s1 or s2 with a true predecessor. Check total length first.
Why doesn't a greedy two-pointer approach work?+
When s1 and s2 both match the current s3 character, you can't know which one to consume. Picking wrong breaks a later match, and greedy never backtracks. DP explores both choices without exponential cost, because states (i, j) repeat.
How hard is this really for an Amazon OA?+
It's a medium. The idea is simple once you see the grid, but candidates stumble on indexing and the length check. With strings capped at 100 each, O(m*n) is trivially fast. Expect the difficulty to be in clean implementation, not in the concept.
Can I solve it with recursion and memoization instead?+
Yes. Recurse on (i, j) with k = i+j implied, and cache results in an m+1 by n+1 table. It's the same complexity as bottom-up DP. Without memoization it's exponential and will time out on the larger inputs.
How do I prepare for this in 48 hours?+
Write the 2D DP from scratch twice, then reduce it to a 1D array. Test the edge cases: all three strings empty, length mismatch, and one source empty. Then do a couple of similar grid DPs like edit distance so the pattern feels familiar.