I have been submitting a few java submissions lately and all of them have been getting Time Limit Exceeded even though I think I am either doing the same solution as the editorial or my solution runs in O(n).
Here are two examples: https://codeforces.com/contest/1334/submission/126210107
https://codeforces.com/contest/1334/submission/126127281
Why is this happening? It's quite discouraging to think I solved a problem with an OK solution then TLE so many times...
Thanks!
Maybe your sort is the issue. See https://codeforces.com/blog/entry/7108
In the second submission, your issue is Arrays.sort, and the infamous Quicksort TLE that can result from specially generated input. These are the Java sorting functions I use.