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.
The reason is that your code is looking for the maximum the looking again to retrieve the index: count.index(max(count))
The code I wrote skip one loop by working directly with the index.
It shows also that when you want efficience, you may have to sacrifice legibility.
So, for the given problem, your solution ace it. For a more general situation, one has to be warry that you implement something very specific to the problem at hand:
Fixed number of bird Ids that are consecutive
Ids are numeric
Would break if "names" where given instead of Ids or if ther was a lot of Ids.
The code you provided is well suited for small diversity of bird tagged by numerical ids.
Cookie support is required to access HackerRank
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 →
Your code is doing more than this one:
The reason is that your code is looking for the maximum the looking again to retrieve the index:
count.index(max(count))
The code I wrote skip one loop by working directly with the index.
It shows also that when you want efficience, you may have to sacrifice legibility.
So, for the given problem, your solution ace it. For a more general situation, one has to be warry that you implement something very specific to the problem at hand:
Would break if "names" where given instead of Ids or if ther was a lot of Ids.
The code you provided is well suited for small diversity of bird tagged by numerical ids.