For those who are getting TLE in C++


#1

Pass vector as const and by reference and you won’t get TLE.


#2

Yeah it worked! Could you please explain why?


#3

Because when you pass don’t pass vector by reference, your function call creates a copy of original vector, so it will take extra time to copy, leading to TLE.


#4

:exploding_head::exploding_head:


#6

Yes, It really worked thanks for sharing …


#7

And why is const nneccesary?


#8

Thanks a lot for sharing man!


#9

Maybe because the original function has declared it as a const vector parameter


#10

It worked, thanks a lot for sharing.