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
This comment is hidden because it contains spoiler information about the solution
I didn't even know you could do this lol
This comment is hidden because it contains spoiler information about the solution
Concatenation is way more readable and it might even be the tiniest amount more efficient
This comment is hidden because it contains spoiler information about the solution
java version is not correct. I managed to solve it only with experimenting with overflow and some guesses about where the author could go wrong (or maybe those who translated kata to java).
For those who intend to do it in Java - use overflow + use only gcd to calculate lcm (I first tried to calculate lcm with BigInteger - haha, fun is it doesn't work, though the answer is correct) + use formula to calculate lcm using gcd loosely (in particular, don't use abs as in formula). Disrespect for not checking the solution before posting.
Very good remark, but everything is not so easy and depends entirely on data.
You can test it yourself, just imagine the list with 10 distinct values, each repeated 1000 times. It's much more easy to 'hashset' it in the start, then sort 10 values, then sorted 10000 values, and only then take only unique ones.
So, one more time, it depends on the data.
still no answer, some kind of magic... :)
oh, thanks bud, I couldn't get it why Comparator.comparingInt(v -> v.getValue()).reversed()) doesn't compile at all, so I used a workaround, and only then saw your solution. Thanks again! :)
exactly, man. I've just wasted 15 minutes trying to write a comparator, but after a few attempts with randomized string without any connection to heads, tails, and bodies, the insight descended on me :)))))
Hi, everyone!
As I understand, all Java reserved words are in lowercase, examples are: import, class, interface, extends, etc. (just google it)
What you both are talking about is just a name of a class in standard Java library ('List'), but neither 'list' nor 'List' are reserved Java words.
That is why you should import java.util.List to tell Java what exactly class you want to use.
And that all means you can create your own class with name 'List' and use it (I can't say it's a good practice, but anyway you can do that). Nobody can stop you from even making a class with name 'list'.
But naming your local variable as 'list' is completely good, especially if the method is small enough and other programmers will not spend hours trying to understand what list you're talking about :)
This problem has a linear-time solution. By resorting to sorting you make it n log n.
ahahha, man, you made my day, I didn't laugh so much last week ))))))
yeah, we all know you're a lifehacker, but who can blame you? The author might have foreseen that result :)