We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My javascript solution. It passes all the test cases, but there aren't that many so I don't how optimal it is and error proof it is.
It is O(n) though.
Explaination:
1. The code essentially gets the frequency of each number in the array and adds it to a map.
2. Then we search through the array to find the key with the value with the highest frequency
3. Then we check to see if that key is miniumum key value with the most frequency in the array.
There is probably some built-in javascript function or some algorithmic techinque that can simplify the code, but it works and it is generally fast. :)
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
My javascript solution. It passes all the test cases, but there aren't that many so I don't how optimal it is and error proof it is.
It is O(n) though.
Explaination: 1. The code essentially gets the frequency of each number in the array and adds it to a map. 2. Then we search through the array to find the key with the value with the highest frequency 3. Then we check to see if that key is miniumum key value with the most frequency in the array.
There is probably some built-in javascript function or some algorithmic techinque that can simplify the code, but it works and it is generally fast. :)