O(n) failed in java CHEFMGX problem in Starters 16

This is the problem CodeChef: Practical coding for everyone
I have written the solution in Java of Complexity O(n)
this is the solution : CodeChef: Practical coding for everyone
I request the viewers to point out what is the mistake in the solution that I got TLE
and the same I wrote in C and got AC :|(CodeChef: Practical coding for everyone)
why even using BufferedReader in java took so long for IO and I request some more time should be given for Java solution. `:)
or the solution should be evaluated without considering IO using predefined functions. :slight_smile:

i am having the same issue, did you found any solution for this problem.

No,
I am using C whenever I get TLE in java.

Hello,

The issue is that , while you are reading the input fast enough, your output is too slow.
You can fix that by utilizing a BufferedWriter of some kind and flush once every test case has been “printed”. Then it should AC, since your program logic is correct.

Here is the adjustment to AC: solution

Hope this helps,

-Nick

1 Like

Thank you very much for helping. :slight_smile: :smiley: