You are viewing a single comment's thread. Return to all comments →
TypeScript solution O(n) by using map
function migratoryBirds(arr: number[]): number { let map = new Map(); let maxCount = 0; let mostFriquentBird = Number.MAX_SAFE_INTEGER; for (let bird of arr) { let count = (map.get(bird) || 0) + 1; map.set(bird, count); if (maxCount < count || (maxCount === count && bird < mostFriquentBird)) { maxCount = count; mostFriquentBird = bird; } } return mostFriquentBird; }
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
TypeScript solution O(n) by using map