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.
it's because first group matching white spaces as well.
!
This comment is hidden because it contains spoiler information about the solution
The math skills were not the point of this kata. This kata does not have arithmetic or any other math related tags attached it besides algorithms, because there is the possibility of a loop. Your reasons for why this kata should be 8kyu are faulty because no first year java course, let alone first course, should be looking at OOP. I find your comment negative and not constructive towards a well implemented kata. Please, in the future, provide positive or constructive feedback based on the parameters of the kata and pursue kata that you would personally enjoy.
The math skills required to solve this are trivial, and possibly one of the first things taught in a student's first java class.
This should certainly be an 8kyu
That makes
pop
an O(n) algorithm andpush
an O(1) algorithm.Using
sort
makespop
an O(1) algorithm andpush
... well since it's inserting a single out-of-place element into a pre-sorted list, with a good sorting algorithm the efficiency should be O(log n). (You could get O(log n) efficiency by performing a binary search to find where to insert the item and then inserting it there, but it's easier to offload it to the built-insort
function and trust that it works efficiently for pre-sorted lists.)So you're trading off one O(1) for another O(1) (no improvement) and a O(log n) for an O(n) (you made it worse).
You would think that JS supported
Object.values
but it doesn't :(