# Why do I get a Time Limit Exceeded?

**URL:** <https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771>\
**Category:** faq\
**Tags:** faq, tle\
**Created:** [March 20, 2013, 4:22pm UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771 "2013-03-20T16:22:50Z")\
**Posts on this page:** 7\
**Page:** 3

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [July 31, 2021, 7:31am UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/41 "2021-07-31T07:31:50Z")

</div>

There’s an out-of-bounds access in the sample testcase:

```auto
[simon@simon-laptop][08:30:16]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling j_o_s_h_101-CRICRANK.cpp
+ g++ -std=c++14 j_o_s_h_101-CRICRANK.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv -fno-sanitize-recover
+ set +x
Successful
[simon@simon-laptop][08:31:00]
[~/devel/hackerrank/otherpeoples]>echo "3
0 1 2
2 3 4
10 10 10
8 8 8
10 0 10
0 10 0
" | ./a.out
j_o_s_h_101-CRICRANK.cpp:12:24: runtime error: index 4 out of bounds for type 'int [3]'

```

Fix that first 🙂

If you need a hint, look _very_ closely at:

`j=0;i<3;j++`

---

<div class="post-metadata">

**Author:** ![vivek\_131](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@vivek\_131](https://discuss.codechef.com/u/vivek_131)\
**Post date:** [August 22, 2021, 5:56pm UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/42 "2021-08-22T17:56:36Z")

</div>

can anyone tell something for fast i/o in javascript ?

---

<div class="post-metadata">

**Author:** ![venkatamanisai](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@venkatamanisai](https://discuss.codechef.com/u/venkatamanisai)\
**Post date:** [January 5, 2022, 10:05pm UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/43 "2022-01-05T22:05:36Z")

</div>

pysco no longer works for python

---

<div class="post-metadata">

**Author:** ![jyot\_150](https://discuss.codechef.com/user_avatar/discuss.codechef.com/jyot_150/32/233124_2.png) [@jyot\_150](https://discuss.codechef.com/u/jyot_150)\
**Post date:** [April 6, 2022, 8:59am UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/44 "2022-04-06T08:59:14Z")

</div>

> [@Why I Get TLE error in simple Question](https://discuss.codechef.com/t/why-i-get-tle-error-in-simple-question/100413):
>
> IN last competition i submitted the solution of the EMAILREM with php and i got TLE error in simple code @admin PLz help why i got that TLE Here is the Link of my Submission :- [CodeChef: Practical coding for everyone](https://www.codechef.com/viewsolution/61851983)

checkout this plz

---

<div class="post-metadata">

**Author:** ![jatin0308\_adm](https://discuss.codechef.com/user_avatar/discuss.codechef.com/jatin0308_adm/32/24644_2.png) [@jatin0308\_adm](https://discuss.codechef.com/u/jatin0308_adm)\
**Post date:** [May 3, 2022, 11:14am UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/45 "2022-05-03T11:14:13Z")

</div>

Hey @jyot_150 👋 ,  
I would recommend you to always take input like the way I did it is safe.

```auto
<?php
$result = trim(fgets(STDIN));

list($a,$b) = explode(' ',$result);

$sub = $a - $b;
echo $sub;
?>

```

---

<div class="post-metadata">

**Author:** ![ilvpython](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ilvpython/32/24644_2.png) [@ilvpython](https://discuss.codechef.com/u/ilvpython)\
**Post date:** [February 15, 2023, 7:37am UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/46 "2023-02-15T07:37:38Z")

</div>

```auto
for i in range(int(input())):
    n,k=map(int,input().split())
    while n>=k:
        n-=k
    print(n)

```

Why am I getting a TLE on this? Problem code: SMOL

---

<div class="post-metadata">

**Author:** ![fawazk](https://discuss.codechef.com/user_avatar/discuss.codechef.com/fawazk/32/177474_2.png) [@fawazk](https://discuss.codechef.com/u/fawazk)\
**Post date:** [February 15, 2023, 3:39pm UTC](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771/47 "2023-02-15T15:39:15Z")

</div>

Hey @ilvpython !  
The problem of TLE occurs when the time that your program runs for exceeds the limit that was set for that particular question.  
For instance in this program, if the value of n is very high (1≤N≤10\*\*9) and k is 1 then it would obviously exceed the set time limit.  
To avoid this u can just use remainder division to get the answer for this qn.  
Also, we must take care of ZeroDivisionError and if the value of the dividend is smaller than the divisor as well.

* * *

for i in range(int(input())):  
n,k=map(int,input().split())  
if n\>=k and k!=0:  
a = n%k  
print(a)  
else:  
print(n)

* * *

[Previous page](https://discuss.codechef.com/t/why-do-i-get-a-time-limit-exceeded/1771.md?page=2)
