Getting TLE int "Match Them"

my code https://ide.codingblocks.com/s/33899
ques link https://hack.codingblocks.com/contests/c/522/942

in this i am computing substrings in O(N3). please tell an alternative method for finding substrings
in this ques

sir please answer my query

https://ide.codingblocks.com/s/34722

Here is my accepted solution for this problem.

Your code will produce a TLE, as you are finding all the possible substring, but finding all substrings will lead to TLE, as string size is around 10^5. So You are supposed to solve this in O(N*X). I have used hashing and little maths to solve this. Please comment if you have any doubts.

sir please add some explanation or comments in the code

https://ide.codingblocks.com/s/34726

I have added the comments. Please take an example if you are not getting it. Do comment if you have any doubts.

1 Like

sir i have just slightly modified the code . it is passing 3 test cases but showing WA on two test cases. sir what’s the mistake in this??
modified code https://ide.codingblocks.com/s/35335