The Find the Original Typed String II interview question is a significantly harder version of the previous problem. You are again given a typed string and need to find the number of possible original strings. However, this version adds a new constraint: the original string must have had a length of at least k. This requirement transforms a simple counting problem into a sophisticated optimization task.
Microsoft and Google use the Find the Original Typed String II coding problem to test a candidate's mastery of Dynamic Programming and optimization. It requires more than just counting blocks; it requires partitioning a target length across several choices. It evaluations your ability to use Prefix Sum optimization to reduce the complexity of DP transitions.
This problem is solved using Dynamic Programming with Prefix Sum Optimization.
dp[i][len] is the number of ways to pick character counts from the first blocks such that their total length is len.dp[i][len] = sum(dp[i-1][len - j]) where .typed = "aaab", .
L1 = 3 ("aaa"), L2 = 1 ("b").Master "Prefix Sums in DP." This is a classic Dynamic Programming interview pattern used whenever a state depends on a range of values from the previous row. It is essential for solving "Hard" category counting problems efficiently.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum White Tiles After Covering With Carpets | Hard | Solve | |
| Number of Beautiful Partitions | Hard | Solve | |
| Number of Ways to Select Buildings | Medium | Solve | |
| Jump Game VII | Medium | Solve | |
| Shortest Common Supersequence | Hard | Solve |