Ad
  • Default User Avatar

    While trying to solve: "Wow, this is a lot harder than I thought"
    After solving, looking at the top-solution: "Oh, yeah, alright..."

  • Default User Avatar

    This is a thing of beauty.

  • Default User Avatar

    Yeah, it's a six at least. My best guess is that people ranking kata's are mostly high ranks that tend to underestimate difficulty.
    I've solved 4kyu's that were easier than this one.

  • Default User Avatar
  • Default User Avatar
  • Custom User Avatar

    I actually googled "CTE" and that popped up as the first result. So I scrolled down, looking for something else, because surely something medical had to be a false positive - but couldn't find anything else. It's not bad as an inside joke, but can I suggest "concussions" to make it clearer as a joke? It really confused me; normally, in untyped languages, the suggested return value is an example of an actually possible return value.

  • Custom User Avatar
  • Custom User Avatar

    If you have a nice tests to share, i would gladly add some

  • Custom User Avatar

    CTE - Chronic Traumatic Encephalopathy
    Some of the ants for sure will injury themselves, by multiple headbumps.

    I fixed the rest :), thanks for the feedback and translation!

  • Custom User Avatar

    Fair enough. 👍

  • Custom User Avatar

    It's all less than ideal. ETA: partially because JS lacks appropriate types, and partially because of questionable design.

    The input should have been is a list of enums, the output a list of unsigned ints. The specific encodings of all those don't actually matter all that much.

    In JS, String behaves much like an Array of Char, so the input isn't all that bad ( and JS doesn't have Enums ETA: except Booleans actually ). The output would have been much better encoded as some Array though ( and JS doesn't have unsigned ints either ETA: actually, it does, for list elements ).

    ETA: ideally, idiomatically, the input would have been an Array of Booleans, and the output an Array of Numbers, or, fancily, an Uint32Array, because anything smaller might would overflow its elements for the N=1e6 case. The input might have been encoded as a ( signed or unsigned ) Int8Array with Left and Right encoded as particular 8-bit numbers ( possibly several; think zero and non-zero ), which would save some storage over said Array of Booleans. Especially for the output, stringifying it is just unnecessary overhead.

    Stringification is always suspect; it's not so much an encoding as it is a serialisation, mainly for display-to-human purposes. At least it has decent language support ( in normal languages. in LC, there is none :P ).

  • Custom User Avatar
  • Custom User Avatar

    You can add your own testcases. ( I did. )

    And yes, there is an O(n) solution.

  • Default User Avatar

    I think there's a O(2n) or even O(n) solution, but the test cases are not really helpful to verify my ideas.

  • Custom User Avatar

    Nice one to figure out how to solve, a little bit of a riddle.

  • Loading more items...