Skip to content

Instantly share code, notes, and snippets.

@Shaddyjr
Created November 16, 2022 07:16
Show Gist options
  • Save Shaddyjr/294aae8d7630362121790ef8feffdec5 to your computer and use it in GitHub Desktop.
Save Shaddyjr/294aae8d7630362121790ef8feffdec5 to your computer and use it in GitHub Desktop.
// 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