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
Wow! Decoding function is so simple and works so good. I couldn't have come up with so easy solution.
This comment is hidden because it contains spoiler information about the solution
Very bad solution. Even though it looks simple and clean, sorting should be never used when not necessary as it is VERY slow. What's more, in this code, 'word' is being sorted in each loop, although it might be sorted once before.
This comment is hidden because it contains spoiler information about the solution