Ad
  • Custom User Avatar

    bro memoization is an overkill here remeber that passwords have an average maximum of 16 digits and a O(N^2) algorithm could do it in 256 cycles which is very low

  • Custom User Avatar

    That's true, but the question also doesn't make sense for float values. How do you fill the output array with 2.3 input arrays?

  • Custom User Avatar

    This code fails for float values. And in the Instruction, it wasn't written that the numbers can only be int.

  • Custom User Avatar

    thats crazy and amazing

  • Custom User Avatar
  • Custom User Avatar

    I like that this solution goes for a very direct interpretation of the task. Using filter keeps the intent easy to follow, and the check based on the word length is simple enough that it reads naturally without extra variables.

    One thing I appreciated is that it avoids unnecessary transformations — the function just keeps the words that match the condition and returns them as-is. That makes the behavior predictable and easy to reason about when scanning the code.

    It also feels like the kind of approach you arrive at after thinking a bit about what “even length” really means rather than just pattern‑matching a common solution, which is always nice to see. Overall it's a small piece of code, but it stays focused and does exactly what it needs to without extra noise.

  • Custom User Avatar
  • Custom User Avatar

    Oh, Applied a lookup-table pattern for constant-time state transition without branching logic. That's great.

  • Custom User Avatar

    thank you for sharing your thoughts. learning by building from scratch is a solid habit.

    it's clear that your goal is to learn from first principles. others, optimize for speed or clarity (or showing library knowledge), so using imports is a valid choice.

  • Custom User Avatar

    I understand that not everyone thinks like me, but what I would like to point out is that a lot of the time, using an import is substantially slower than just writing your own function. Not only that, you get to learn something new and think through the problem through "first principles". Personally whenever I write software I try to rely on external libraries as little as possible, mostly because I like to treat it as a learning exercise and I would encourage others to do the same.

  • Custom User Avatar

    We're here to enjoy the process of solving problems on this platform, regardless of our methods.

    That statement about having to write every algorithm from scratch isn't accurate.

  • Custom User Avatar

    Although it's been mentioned that this is not a best practice solution, I would like to point out that using imports to solve every problem defeats the purpose of this site. We are supposed to practice writing our own algorithms from scratch.

  • Custom User Avatar

    Nice! Had to dig into floating point numbers passed into Array.slice(). It seems to truncate, not round. Very cool solution!

  • Custom User Avatar

    This short solution looks neat but can break on UTF-8 characters, because [..1] slices bytes, not Unicode scalar values.

    Examples:

    • Multi-byte characters, like cyrillic "Привет" will panic.
    • Emoji: "😀" (4 bytes)
    • Asian characters / ideograms: "汉", "あ", "한" (2–3 bytes)
    • Latin letters with diacritics: "é", "ü", "ñ" (2 bytes)
    • Combining characters / accents: "á" (letter + accent, 2+ bytes)

    Using [..1] on these will panic, because it slices bytes, not Unicode scalar values.

  • Custom User Avatar

    but this doesn't work for input array [2,2,3,3] or [2,2,2,3,4,5]. Am I missing something?

  • Loading more items...