Why do I get a Time Limit Exceeded?

,

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

[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 :slight_smile:

If you need a hint, look very closely at:

j=0;i<3;j++

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

pysco no longer works for python

checkout this plz

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

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

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

$sub = $a - $b;
echo $sub;
?>
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

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)


1 Like