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 your optimized program. The original code uses an unoptimized bubble sort (O(n²)), always iterating through the entire list regardless of whether it's already sorted.
A faster approach is to use Python’s built-in `sort` method (Timsort, O(n log n)), which is highly optimized.
I’ve preserved your print statements and function signature.
**Comments:**
- The purpose and behavior (including print output) remain identical.
- This approach is significantly faster for all but the smallest lists.
- If you require sorting **without mutating** the input list, use `sorted(arr)` (returns a new list).
Let me know if you need to preserve the original or add more features!
0 commit comments