whats Making it TLE

codeforces
div3
java

#1

check

problem


#2

It depends on complexity of function s.equals(e) which i think is O(min(s.length,e.length)). So your codes complexity turns out to be O(min(s.length,e.length)*s.length).
Now for s.length =10^5 Complexity for worst case can be O(10^10).

That’s the reason for TLE.


#3

What will be the alternative , how can I remove TLE


#4

The thing in this question is you can’t remove right side of string. So we will start from back of both strings , Lets assume our strings to be “codechef” and “fdhef”, During our first iteration ‘f’ is common in both strings So During the process of removing, this position from strings won’t get removed. Same for ‘e’ and ‘h’ but now character ‘e’ and ‘d’ aren’t same So what we do is break he loop as we possibly can’t get another character in our answer string. Now what our answer should be is s.length+e.length-2*x.
where x is number of same back character we got.