Find Lucky Integer in an Array LeetCode solution in JavaScript

1
// time O(n) space O(n)
2
var findLucky = function (arr) {
3
let max = -1;
4

5
const map = {};
6

7
for (const number of arr) {
8
if (map[number]) {
9
map[number] += 1;
10
} else {
11
map[number] = 1;
12
}
13
}
14

15
for (const key in map) {
16
if (Number(key) === map[key] && map[key] > max) {
17
max = map[key];
18
}
19
}
20

21
return max;
22
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0