What should be the approach of this problem?

i was trying to insert the indexes of all characters of both the strings into 2 different maps.
but after that what to do, i could not figure out…
please help a little bit

@sirraghavgupta
We make two seperate maps for A and B.
Let’s call them Amap and Bmap.
These maps are of type <char,int> and each store the frequency of each character in the strings. Initially both are empty.
Fill Bmap by traversing over string B.
Keep Amap empty for now.

Now comes the main part.
Traverse over string A. Update Amap according to the current character.
for(int i=0;i<A.size();i++)
//Insert each element of A into Amap with its frequency
Amap[A[i]]++;

At each iteration check whether the frequency of every character in Bmap is more in Amap or not. That is , check whether string A traversed so far whose frequencies are stored in Amap are more than frequencies in Bmap.
If not , repeat the iteration.
If however it is so , then start decreasing the length of A from left by removing redundant characters from the left. Calculate length of string at each instance and update your answer accordingly. Try this out and let me know if you need any help.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.