Can anyone give the idea how to solve this problem please

https://www.codechef.com/JUNE20B/problems/CONTAIN
i just want which algorithm should i learn