Same Logic but TLE in java and AC in C++ in SKMP

hi @rishup_nitdgp @triplem5ds @daniel_1999
I did this question SKMP,
i tried the same logic in JAVA and then in c++, then why i am getting TLE in java and AC in c++?? if it getting accepted in c++ then it also meant to be accepted in JAVA.
https://www.codechef.com/viewsolution/36578802 -java
https://www.codechef.com/viewsolution/36724960 - c++

this happened 2nd time with me, TLE in java and AC in C++
if java needs more time then i think problem setter should increase time limit for JAVA.

In Java, isn’t appending to a String an O(N) operation?

 string res="";
 ...
 res+=temp;
3 Likes

ya, and in c++ its O(1)?

Yes.

2 Likes

ok. thank you,

1 Like