Skip to content

Missing Test Case - 169. Majority Element #31235

@Sudeep-More

Description

@Sudeep-More

LeetCode Username

Sudeep_More

Problem Number, Title, and Link

https://leetcode.com/problems/majority-element/description/

Bug Category

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

Bug Description

When we have input = [3,2,2,3] then what should be the output? 2 or 3?

Language Used for Code

Swift

Code used for Submit/Run operation

func majorityElement(_ nums: [Int]) -> Int {
    var freq: [Int: Int] = [:]
    var maj = nums.count / 2
    
    for num in nums {
        freq[num, default: 0] += 1
        if freq[num]! > maj {
            return num
        }
    }
    return -1
}

Expected behavior

It is returning -1, which is correct but this test case is missing.

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions