LeetCode-Feedback / LeetCode-Feedback

713 stars 347 forks source link

Missing Test Case - 169. Majority Element #27822

Closed rifazjeoffrey78 closed 6 days ago

rifazjeoffrey78 commented 1 week ago

LeetCode Username

rifazjeoffrey

Problem Number, Title, and Link

  1. Majority Element https://leetcode.com/problems/majority-element

Bug Category

Missing test case (Incorrect/Inefficient Code getting accepted because of missing test cases)

Bug Description

what if input is [1,1,2,3,4,5,6]. Answer should be 1 but 6 may be chosen

Language Used for Code

Python/Python3

Code used for Submit/Run operation

def majorityElement( nums: list[int]) -> int:
        count = 0
        candidate = 0

        for num in nums:
            if count == 0:
                candidate = num
                count = 1
            elif candidate == num:
                count += 1
            else:
                count -= 1

        return candidate

Expected behavior

should return 1

Screenshots

No response

Additional context

No response

exalate-issue-sync[bot] commented 1 week ago

LeetCode Support commented: Thank you for reaching out with your concern. Upon reviewing your report, it appears there may be some confusion regarding the problem statement. The problem assumes that the input array always contains a majority element, which means an element that appears more than ⌊n / 2⌋ times. In your example [1,1,2,3,4,5,6], no element appears more than 3 times, so this input would not meet the problem constraints as given in the description. If you have any further questions or need additional clarification, I recommend revisiting the problem statement and reviewing the provided examples. Please let us know if there's anything else we can do for you.

LeetCode Support Team