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 challenge explicitly states there will never be more than 5. If the number were open ended, I'd optimise for that. As it is, there's no point. Pointless optimisation is a waste of time, in real work even more so than in toy challenges. Your solution does more work than mine and doesn't have to because there's no gain here.
"And BTW your code doesn't use nested lists, which is the subject of this assignment.)"
A fixed limit of 5 is also part of the assignment but you pointlessly ignored that.
Nested lists are the wrong solution for this challenge. That's typical of the author, most of whose challenges are poor quality and poor teaching material. Fortunately, there's zero requirement to use nested lists.
I find your solution ugly and verbose because all the logic is tied up in one long if/else statement. If I wanted to optimise for saving space (not necessary with a guaranteed limit of 5), i'd simply adjust the code so that when a value is pruned from top2, its names are pruned from dict and all future entries for that score are ignored. And because my code isn't a long chain of if/else, that's an easy change to make.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nested Lists
You are viewing a single comment's thread. Return to all comments →
"If you have a gazillion names in the input"
The challenge explicitly states there will never be more than 5. If the number were open ended, I'd optimise for that. As it is, there's no point. Pointless optimisation is a waste of time, in real work even more so than in toy challenges. Your solution does more work than mine and doesn't have to because there's no gain here.
"And BTW your code doesn't use nested lists, which is the subject of this assignment.)"
A fixed limit of 5 is also part of the assignment but you pointlessly ignored that.
Nested lists are the wrong solution for this challenge. That's typical of the author, most of whose challenges are poor quality and poor teaching material. Fortunately, there's zero requirement to use nested lists.
I find your solution ugly and verbose because all the logic is tied up in one long if/else statement. If I wanted to optimise for saving space (not necessary with a guaranteed limit of 5), i'd simply adjust the code so that when a value is pruned from top2, its names are pruned from dict and all future entries for that score are ignored. And because my code isn't a long chain of if/else, that's an easy change to make.