Timeout in java but accepted in python

timeout

#1

I was solving the problem https://www.codechef.com/MAY19B/problems/WTBTR
and it got time limit exceeded in java but when i submitted the same logic in python solution got accepted!!
Why is this happening?


#2

That’s because of time multiplier. No worries, I once even passed the time limit by translating from C++ to Python (which has 5x multiplier).


#3

But does that means that the solution can be optimized further?


#4

I solved it in java in 0.36 sec whereas time limit is 2sec (for java)
Edit:- are u using scanner? if yes then don’t. Use bufferedReader or fast io


#7

Use Buffered Reader instead of Scanner. :blush:


#8

My complexity is O(n*logn) and it exceeds 2 sec even with Buffered Reader.


#9

Then I guess you have to optimize further.


#10

Are you about the code style (e.g. BufferedReader instead of Scanner, arrays instead of lists, print("\n") instead of println()) or about the algorithm complexity (probably O(n*logn) is not an optimal solution)?