TRIP2 - Getting TLE

Codelink : CodeChef: Practical coding for everyone
I’m getting TLE for Second sub-task. Can anyone help me explain why is that so ?

I don’t know much about Java, but what is the time complexity of String.concat()? I thought Java strings were immutable, in which case appending an element at a time will be O(N^2) for appending N elements.

1 Like

It worked! I used StringBuilder which offers O(n) complexity for appending n elements as it is mutable.
Thanks @ssjgz :slight_smile:

1 Like

Happy to help :slight_smile: 20 characters blah-de-blah