




Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Which conditions have to been met in order to be impossible to form the target string?
If there exists a character in the target string which doesn't exist in the source string then it will be impossible to form the target string.
Assuming we are in the case which is possible to form the target string, how can we assure the minimum number of used subsequences of source?
For each used subsequence try to match the leftmost character of the current subsequence with the leftmost character of the target string, if they match then erase both character otherwise erase just the subsequence character whenever the current subsequence gets empty, reset it to a new copy of subsequence and increment the count, do this until the target sequence gets empty. Finally return the count.