Optimize Quick Sort, N-Sum, and fix bug in Is Palindrome#2745
Optimize Quick Sort, N-Sum, and fix bug in Is Palindrome#2745DhruvrajSinhZala24 wants to merge 2 commits into
Conversation
DhruvrajSinhZala24
commented
Mar 19, 2026
- Quick Sort: Added Median-of-Three pivot selection and Insertion Sort for small subarrays.\n2. N-Sum: Refactored to reduce redundant sorts and copies using recursion with indices.\n3. Is Palindrome: Fixed potential IndexError and improved efficiency.
1. Quick Sort: Added Median-of-Three pivot selection and Insertion Sort for small subarrays.\n2. N-Sum: Refactored to reduce redundant sorts and copies using recursion with indices.\n3. Is Palindrome: Fixed potential IndexError and improved efficiency.
…thms Optimize Quick Sort, N-Sum, and fix bug in Is Palindrome
keon
left a comment
There was a problem hiding this comment.
Verified locally: test_array.py, test_sorting.py, and test_string.py all pass (116/116). Algorithmically the changes look fine — median-of-three + insertion-sort threshold for quicksort is a standard, well-motivated optimization, and the n-sum refactor to indices rather than slicing is a real improvement.
A few process notes for the maintainer:
-
Bundling. Three unrelated changes (quicksort optimization, n-sum refactor, is_palindrome bugfix) in a single PR makes review and revert harder. Splitting into three PRs would be much friendlier to review.
-
Overlap with #2749. The is_palindrome portion duplicates #2749, which is a tighter, more focused fix to the same root cause (
_remove_punctuationstripping digits). I'd suggest landing #2749 first and dropping the is_palindrome changes from this PR. -
n-sum behavior. The refactor drops the
sorted([...])call on each appended tuple that the original_append_elem_to_each_listhad. The new code relies on the input being sorted (which it is, via the upstreamnums.sort()) so output order is preserved — that's correct, but worth a one-line comment in the code to flag the invariant for future readers.
Not blocking — just suggesting a cleaner split.