Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Heap is really not good solution in this situation. it does not help the algorithm become all that much more efficient. Using a heap instead would barely show significant gain in performance, bar certain very narrow situations. Using heap here to reduce from O(2n) to O(n), while using a loop is already so elegant and simply, is impractical (in most cases), in short.
That being said, while this solution is elegant, some understanding of time and space complexity is required for beginners to make the most of it. Blindly following code shortening practices is not good software engineering practice.
I was going to say something similar, it's much more efficient to leverage a heap. Not nearly as pretty tho
Please use spoiler flag next time.
This comment is hidden because it contains spoiler information about the solution