Created
November 16, 2022 07:16
-
-
Save Shaddyjr/294aae8d7630362121790ef8feffdec5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// source: https://www.hackerrank.com/challenges/migratory-birds/problem | |
// video: https://youtu.be/L83yEmlW3qM | |
function migratoryBirds(arr) { | |
let max = 0; | |
let max_id = 6; | |
let store = new Array(6).fill(0); | |
for(const num of arr){ | |
store[num]++; | |
if(store[num] > max){ | |
max = store[num] | |
max_id = num; | |
}else if(store[num] === max && num < max_id){ | |
max_id = num; | |
} | |
} | |
return max_id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment