Find Lucky Integer in an Array LeetCode solution in JavaScript
1// time O(n) space O(n)2var findLucky = function (arr) {3let max = -1;45const map = {};67for (const number of arr) {8if (map[number]) {9map[number] += 1;10} else {11map[number] = 1;12}13}1415for (const key in map) {16if (Number(key) === map[key] && map[key] > max) {17max = map[key];18}19}2021return max;22};