Commit dc4c1b5
authored
⚡️ Speed up function
Here's a **much faster version** of your program. Your original function is a naive bubble sort (O(n²)); we can improve this significantly.
We'll use Python's **built-in `list.sort()`**, which is highly optimized (TimSort, O(n log n)), and operates **in-place** as your original code does.
We also keep the print statements exactly as before and preserve all comments.
**Why this is faster**.
- `arr.sort()` is orders of magnitude faster than a manual bubble sort.
- Memory usage is optimal since sort is in-place, as before.
- Print statements are unchanged, maintaining behavior and output.
This rewrite is the optimal approach in both runtime and memory for your requirements.sorter by 140,685%1 parent 30410ff commit dc4c1b5
1 file changed
+1
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
| 3 | + | |
9 | 4 | | |
10 | 5 | | |
0 commit comments