Repository navigation
Fix quick_select crashing on non-positive rank in median_of_medians.py - #15544
Open
Saadanjum0 wants to merge 1 commit into
Open
Saadanjum0 wants to merge 1 commit into
Saadanjum0 wants to merge 1 commit into
Conversation
quick_select only rejected target > len(arr), so a rank of 0 or negative fell through to median_of_medians() on a progressively smaller list until it indexed an empty list, raising IndexError instead of returning -1 like other invalid input. Added doctests covering target = 0 and target = -1.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change
quick_selectinsearches/median_of_medians.pyonly guarded againsttarget > len(arr). A rank of0or a negative rank slipped past thatcheck and was passed into
median_of_medians()on a shrinking slice ofarruntil it indexed an empty list, raising an unhandledIndexErrorinstead of returning
-1the way other invalid input already does.Fixed by rejecting
target <= 0alongside the existing upper-boundcheck, and added two doctests (
target = 0,target = -1) thatreproduce the crash before the fix and pass after it.
Checklist