Skip to content

Bug Report for quickSort #4034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
robskrob opened this issue Apr 11, 2025 · 0 comments
Open

Bug Report for quickSort #4034

robskrob opened this issue Apr 11, 2025 · 0 comments

Comments

@robskrob
Copy link

robskrob commented Apr 11, 2025

Bug Report for https://neetcode.io/problems/quickSort

The exercise is telling me that my submission is wrong.My solution is also "stable" unintentionally. Here is my code for quick sort:

class Pair:
    def __init__(self, key: int, value: str):
        self.key = key
        self.value = value
        
class Solution:
    def quickSort(self, pairs):
        lastIndex = len(pairs) - 1

        left = []
        right = []

        if lastIndex == -1:
            return pairs

        pivot = pairs[lastIndex]

        for i in pairs[0:lastIndex]:
            if i.key <= pivot.key:
                left.append(i)
            else:
                right.append(i)

        return self.quickSort(left) + [pivot] + self.quickSort(right)

Is there something wrong with my code that fails to meet the requirements? I believe that my solution sorts the list correctly.

Given a list of key-value pairs, sort the list by key using Quick Sort. For each partitioning step:

  1. Use the right-most element as the pivot.
  2. Elements less than the pivot should be placed to the left of the pivot, and elements greater than or equal to the pivot should be placed to the right of the pivot.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant