4 ms·
> If it doesn't, then why not simply move the sort out of the loop? Yup, they should definitely move the sort outside of the loop. Shifting is O(N) so overall
by nateb2022 1y ago
> If it doesn't, then why not simply move the sort out of the loop?
Yup, they should definitely move the sort outside of the loop. Shifting is O(N) so overall complexity would be O(N^2) but they could avoid shifting by reverse-sorting outside the loop and then iterating backwards using pop()