You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here’s a much faster rewrite of your `sorter` function. Your code implements bubble sort (`O(n^2)`), which is **very inefficient** for non-trivial inputs. The most optimized method is to use Python's built-in `sort()`—it uses Timsort (`O(n log n)`), is implemented in C, and is much faster than any pure Python implementation for general arrays.
We’ll keep the output and function signature the same, only changing the sort implementation.
**Notes:**
- Built-in `.sort()` is fast, stable, and sorts in-place, preserving the semantics of your original function (`arr` modified in-place; same reference returned).
- All comments are preserved, as required.
This will **dramatically improve** performance for all but tiny arrays.
0 commit comments