-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/majority-element-ii
Description:
My output matches the expected output, but the console is returning "Wrong Answer"; submission is, however, accepted.
Steps to reproduce:
Run the following JavaScript:
class Solution {
/**
* @param {number[]} nums
* @return {number[]}
*/
majorityElement(nums) {
const numsMap = this.createMap(nums)
const numElems = nums.length / 3
const majorityElems = []
for (const [key, val] of numsMap) {
if (val > numElems) {
majorityElems.push(key)
}
}
return majorityElems
}
createMap(arr) {
const map = new Map()
for (const elem of arr) {
if (map.has(elem)) {
map.set(elem, map.get(elem) + 1)
} else {
map.set(elem, 1)
}
}
return map
}
}
Screenshot:

Metadata
Metadata
Assignees
Labels
No labels