There are two strings, s and t.
Perform two operations with string s:
- Working from Left-to-Right delete each occurance of t in s until there are no more occurances of t. Count each deletion.
- Working from Right-to-Left delete each occurance of t in s until there are no more occurances of t. Count each deletion.
Return Greater of the two counts.
Example: s="bcbbc" t="b" - From left To Right: s reduces to bcbbc->cbbc->cbc->cc, The number of moves is three - From Right To Left: bcbbc->bcbc->bcc->cc , The number of moves is three So ans is max(L-to-R,R-to-L)=3;
Example: s="aabb" t="ab" - From left To Right: s reduces to aabb->ab->"", The number of moves is two - From Right To Left: s reduces to aabb->ab->"", The number of moves is two So ans is max(L-to-R,R-to-L)=2;
Constraints: 1<=length(s)<=2*10^4 1<=length(t)<=100
snaps of the problem: https://imgur.com/a/uvOgvbh