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.
This comment is hidden because it contains spoiler information about the solution
Thanks for taking the time to comment on this translation. The tests and the solution in this Java translation agree with the description of the kata and the suggested solutions in any language. The description is obviously concerned with removing numbers from the text, that's mentioned 3 times and is exactly what every other translation is doing. It's not implied anywhere that any other special character apart from ones in the provided list should be removed. If that's the case, it's not explicitly mentioned anywhere that we must keep letters for example but apparently we must. Therefore, "just remove numbers" is the correct interpretation of this description, in line with what most solvers/translators understood and I am happy if the tests test that. After browsing other solutions for a few minutes, I am afraid you might be the only one that approached by keeping some valid characters instead of just removing numbers. That's certainly a creative approach but I am not convinced it's correct per the description.
Most solutions do
distinct().sorted()
. For whoever might be interested in performance, the order of these matters.distinct
beforesorted
will create aHashSet
with all elements to ensure uniqueness. This is avoided ifsorted
comes before. The stream implementation uses the fact that equal elements are now next to each other and can efficiently pick unique ones.E.g. https://stackoverflow.com/a/43807329/1413133
seems fine now
Not really.
max
method uses?
An integer subtraction could be skipped for the case when there isn't enough capacity, although the compiler (Hotspot) is likely to do this optimization anyway.
You may also like my other date and time kata http://www.codewars.com/kata/everybody-hates-mondays
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Please don't count semicolons in imports statements. That's some of the ugliest code I've ever written.
Seems like we were both inspired by the same Stackoverflow answer
It'd be more fun if you didn't count semicolons at import statements.
Avoiding imports altogether is bad practic and not idiomatic java
and makes it difficult working on IDEs that will (of course) auto-import.
Yes my solution is accepted now. Thanks guys!
Two strings may have more than one longest common subsequence. When this occurs, return any of them.
I am doing that and tests fail (Java). E.g.
a = "bwqajykparaclbzhrtvk"
b = "trtskldzrbswrdxxikdi"
expected:<k[rb]rk> but was:<k[lz]rk>
Such a solution would pass the tests and be more efficient.
But it wouldn't be correct by the requirements: "Return None if it is not possible to define only one of such values".
So if the array is
[5, 3, 3, 1]
we should return 1 as closest to zero and we can only do that if we cover the whole array.If we stop for any number at equal distance to the current closest to zero we would stop for 3 and return None.
It's what dinglemouse complains about at my first solution that did what you suggested.
You are correct.
I didn't think much about the requirement of returning null if closest isn't unique because it's a bizzare requirement
and this passed the tests anyway.
I submitted another solution.
Loading more items...