medium2-D Dynamic ProgrammingMicrosoft
Weave Checker
A merge-sort tool verifies whether a long string could have been produced by interleaving two shorter strings while preserving each one's order.
Given strings s1, s2, s3, return true iff s3 is a valid interleaving of s1 and s2 (preserving order).
Choose approach
T
F
F
F
F
F
row
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
1/7
Narrationstep 1 of 7
Row 0 filled (used s1[0..-1]).
Variables
i=0
How to think about it
- Length check first.
- Each dp[i][j] has at most 2 incoming transitions.
Edge cases to catch in interview
- Empty s1, s2, s3 -> true.
- Length mismatch -> false.
Examples
Example 1
true{"s1":"","s2":"","s3":""}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed