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.
Even if the code is pretty beautiful, calling sorted on the whole list makes it not linear at all.
Means, you made a beautiful code which is short and all but sacrificing time efficency.
Even if it'd become more verbose, finding the second_highest grade does NOT require the list to be sorted. It can be done in O(n)
Another thing is, if you sort the result list after you selected it instead of again sorting the whole lsit and then selecting the results, it also increase efficency by a lot.
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 →
Even if the code is pretty beautiful, calling sorted on the whole list makes it not linear at all.
Means, you made a beautiful code which is short and all but sacrificing time efficency. Even if it'd become more verbose, finding the second_highest grade does NOT require the list to be sorted. It can be done in O(n)
Another thing is, if you sort the result list after you selected it instead of again sorting the whole lsit and then selecting the results, it also increase efficency by a lot.