You are viewing a single comment's thread. Return to all comments →
Actually len() also matters, especially inside the loop. I had
inversions += len(arr0[i0:])
instead of
inversions += len0 - i0
and it was timing out because when slicing, Python creates a copy, making it O(n) opperation.
Thank you for the code.
Seems like cookies are disabled on this browser, please enable them to open this website
Merge Sort: Counting Inversions
You are viewing a single comment's thread. Return to all comments →
Actually len() also matters, especially inside the loop. I had
instead of
and it was timing out because when slicing, Python creates a copy, making it O(n) opperation.
Thank you for the code.