Not getting any idea

Hello …

I am trying to solve this question from hackerearth…

I got only a brute force idea…
So i tried to look into other’s solution…
This solution … https://www.hackerearth.com/submission/52006916/
I tried to understand but couldn’t.
Can you explain what kind of algorithm is being used or what is the logic.
Thanks

we do preprocessing on the strings as we have to encounter multiple queries. We can store the number of characters of string B that matches till each index of string A in both the forward and backward directions, in two separate arrays. Finally we can say the answer is Yes, if the following equation holds, otherwise No:
forward[i-1] + backward[j+1] >= length(B).

This works because we are removing A[i]…A[j] from A and want to know the sum of number of characters of B that match in A
from A[1]…A[i-1] and A[j+1]…A[len], which is a subsequence if this sum is atleast the length of string B.

Yaa…
I got it … Thank You very Much…
You have explained really well…
I wish each editorial of hackerearth can be like that … :slight_smile:
Thanks

no problem :slight_smile:
if this solves your doubt please mark it as resolved