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.
It traverses the entire data set twice, the second time to extract the scores (which it already saw in the first traversal, so the second traversal is unnecessary).
Turning the list of scores into a set and then sorting the result and extracting the second one is significantly less efficient than simply traversing the list once and keeping the lowest two numbers you see, then discarding the lowest once you've reached the end of the list.
Sorting the entire list of students (despite the fact that most of them probably didn't have the second lowest score and won't be printed out) and then excluding the students with the wrong score is less efficient than excluding the wrong students and sorting only the right students.
Concatenating all the names and printing the result as one big string is less efficient (both in terms of time taken and memory used) than simply iterating over the names and printing each one in turn.
It is simple but an efficient solution can be just as simple and at least as readable.
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 →
It's quite inefficient.
It is simple but an efficient solution can be just as simple and at least as readable.