# How to handle TLE in Java and C++?

**URL:** <https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285>\
**Category:** general\
**Created:** [May 26, 2022, 5:15pm UTC](https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285 "2022-05-26T17:15:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamtheone\_kool](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@iamtheone\_kool](https://discuss.codechef.com/u/iamtheone_kool)\
**Post date:** [May 26, 2022, 5:15pm UTC](https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285/1 "2022-05-26T17:15:48Z")

</div>

Please tell me How to handle TLE in Java and C++  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![hrishik85](https://discuss.codechef.com/user_avatar/discuss.codechef.com/hrishik85/32/24644_2.png) [@hrishik85](https://discuss.codechef.com/u/hrishik85)\
**Post date:** [May 27, 2022, 6:51am UTC](https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285/2 "2022-05-27T06:51:36Z")

</div>

@iamtheone_kool - You can check this out - [Why do I get a Time Limit Exceeded? - #2 by admin](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/2).  
If you are getting TLE → in most cases you need to reduce the complexity of your code. For example → you are running a loop within a loop → but the constraints mean that you will have to find an approach where a single loop suffices. This is problem specific → check out ‘Other Users’ submissions’ to understand how other users got an AC.

---

<div class="post-metadata">

**Author:** ![linsayton](https://discuss.codechef.com/user_avatar/discuss.codechef.com/linsayton/32/103385_2.png) [@linsayton](https://discuss.codechef.com/u/linsayton)\
**Post date:** [May 27, 2022, 12:33pm UTC](https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285/3 "2022-05-27T12:33:36Z")

</div>

This post was flagged by the community and is temporarily hidden.

---

<div class="post-metadata">

**Author:** ![iamtheone\_kool](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@iamtheone\_kool](https://discuss.codechef.com/u/iamtheone_kool)\
**Post date:** [May 30, 2022, 8:56am UTC](https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285/4 "2022-05-30T08:56:38Z")

</div>

hmm, thanks, this post by the admin was great thanks 🙂

---

<div class="post-metadata">

**Author:** ![termii](https://discuss.codechef.com/user_avatar/discuss.codechef.com/termii/32/355675_2.png) [@termii](https://discuss.codechef.com/u/termii)\
**Post date:** [June 1, 2022, 9:41pm UTC](https://discuss.codechef.com/t/how-to-handle-tle-in-java-and-c/101285/5 "2022-06-01T21:41:05Z")

</div>

there are some things to consider when using Java.

**Input reading** with standard libraries can be so slow that it may cause a TLE. Using some kind of custom Scanner class is a must.

> **[How to read input in Java — tutorial - Codeforces](https://codeforces.com/blog/entry/7018)**
>
> Codeforces. Programming competitions and contests, programming community

**sorting** arrays of primitive types will be done viá Quicksort in Java. Quicksort has a worst case of O(n²), this is too slow for many problems. Forcing Java to use Mergesort instead is another must.

> **[How to sort arrays in Java and avoid TLE - Codeforces](https://codeforces.com/blog/entry/7108)**
>
> Codeforces. Programming competitions and contests, programming community
