VipinSharma01's blog

By VipinSharma01, history, 2 months ago, In English

I have seen sometimes when I sort array it gives TLE but when I sort ArrayList code gets accepted why so?? I have added 2 codes in the first one I have used array, got TLE and in the second one i use arraylist and it got accepted.

(I googled but did not found the reason)

TLE when I used array: https://codeforces.com/contest/600/submission/104404543 Accepted when I use ArrayList: https://codeforces.com/contest/600/submission/104404966

Thanks.

 
 
 
 
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it
»
2 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Collections.sort() does some variant of merge sort, while Arrays.sort() for int array is quicksort whose worst cases is quadratic. However, Arrays.sort() for Integer array is merge sort.