




Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
We can use dynamic programming to find the answer. Create a 0-indexed dp array where dp[i] represents the maximum number of moves needed to remove the first i + 1 letters from s.
What should we do if there is an i where it is impossible to remove the first i + 1 letters?
Use a sentinel value such as -1 to show that it is impossible.
How can we quickly determine if two substrings of s are equal? We can use hashing.