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.
Fair enough; "inefficient" was a poor choice of word. I was referring more to DRY, and should've said "redundancy".
The second slice is taken only once during the whole execution process, and having an additional
O(n)
operation in anO(n^2)
algorithm doesn't really change anything.len
is O(1)...In three lines of code you manage to calculate the length of
s
three times, the substrings[:i]
twice, and the pattern lengthlen(s) // i
twice. So much inefficiency packed into such a tiny space, it's actually impressive.I have haters? thats cool.
thx for the snippet
Clever Kata. Don't listen to the haters, this is a great exercise. However,
The formatting of this passage is pretty gnarly. Since this passage isn't part of the key to the puzzle, I'd recommend rewriting:
There is an upper limit of occurrence for the highest possible value. So we are taking the first n of the sorted elements. The highest possible value can be in the original array more times before other smaller numbers which should be accepted instead.
Obviously this can be done with a simple dictionary, but I rarely ever use
Enum
so I figured I'd practice. Genuinely curious if usingEnum
here is best practices...?Oooof, I'm embarassed by my pattern now. TIL about
\2
.Super confused by the tests and the description. Are we taking the first
n
unique minimum elements? Or just the firstn
of the sorted elements? Or something else entirely? My current solution only deviates in the last few elements of these long lists, which seems like super strange behavior to me. An example:In the "correct" solution you can clearly see that an 8 is left out. In mine, the last four elements are
[8, 4, 6, 6]
and in the "correct" solution the last four are[4, 6, 6, 1]
so clearly the two are just offset by this one extra element in mine, BUT the "correct" solution includes other 8s, so clearly the "correct" solution considers 8 to be one of then
minimum elements... I don't understand why the "correct" solution throws this particular 8 out when others are let in...Slicing is your friend!
Slicing is your friend!
This comment is hidden because it contains spoiler information about the solution
Two list comps is bad. Rebinding a keyword is even worse. Unreal that this is the top solution.
This comment is hidden because it contains spoiler information about the solution
Loading more items...