Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use dynamic programming.
The state of the DP can be the current index and the remaining characters to delete.
Having a prefix sum for each character can help you determine for a certain character c in some specific range, how many characters you need to delete to merge all occurrences of c in that range.