Ad
  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I didn't even know you could do this lol

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Concatenation is way more readable and it might even be the tiniest amount more efficient

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    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.

  • Default User Avatar

    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.

  • Default User Avatar

    still no answer, some kind of magic... :)

  • Default User Avatar

    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! :)

  • Default User Avatar

    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 :)))))

  • Default User Avatar

    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 :)

  • Default User Avatar

    This problem has a linear-time solution. By resorting to sorting you make it n log n.

  • Default User Avatar

    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 :)