How to determine if my program is gonna give TLE ??

I have recently tried solving the questions in the long challenge, in the greedy candidates questions I tried implementing it in java and got 2.1s and TLE, how to understand why it gave TLE and how to overcome it??

1 Like

Dont use scanner class for taking input. In that 2 second time, I bet that a huge chunk of your time is taken in just taking input. Google and copy the Fast I/O template of java, and re-run the same code.

Use Buffer Reader or any other fast I/O template for taking input.
Also, in case you didn’t know about time complexity, this link will be helpful!

please use fast i/o

thanks a lot!

thanks a lot!

thanks a lot!

I found an answer for this question in detail here

I hope you will find it helpful.