Timeout in java but accepted in python

I was solving the problem CodeChef: Practical coding for everyone
and it got time limit exceeded in java but when i submitted the same logic in python solution got accepted!!
Why is this happening?

1 Like

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).

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

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

2 Likes

Use Buffered Reader instead of Scanner. :blush:

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

Then I guess you have to optimize further.

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)?