Ad
  • Custom User Avatar

    You also have O(n), if you want to find solutions with the best result, then there are other sites for this, where this is emphasized. Or you can post 2 solutions. One is short, the other is optimal.
    For all arrays of type [0,0,0,1] you have the same result.

    I don't think you'll get extra points for fast execution here.

  • Custom User Avatar

    SENSENEL, this is a very good question. Unfortunately, it is a brute force solution that is not optimal. See my solution which is 8 character longer (when removing spaces that were added for readability) but has an optimal O(n) time and O(n) space complexity.

    I created a bechmark with a simple case, 1000 elements array, with no matching numbers (to test the worst-case scenerio of searching everything, instead of relying on luck to find the mathing numbers in first iterations). It compares my solution, Niksonman's solution and your solution: jsbench.me/23l4lcraig/1 - try changing the 1000 to million and see what happens.

    @SENSENEL, you asked a very good question. In real recruitment tasks, the tests are more complex than here and also check the time and space complexity, so it is important to always keep it in mind. For example try how all of those solutions would pass the tests on AlgoExpert, which has exactly this task as its first task in their Easy list.

  • Default User Avatar

    Same here - after attempting my first try from yesterday, just to see and analyse why those randos fail, it suddenly works!
    OoooK ... ?
    Maybe you guys check again - seems the author worked it out ...

  • Custom User Avatar

    Description should probably mention that array must be sorted in lexicographical order.

  • Custom User Avatar
  • Custom User Avatar

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

  • Custom User Avatar

    Same for python

  • Default User Avatar
  • Default User Avatar

    ok, this was kind of asking myself "in what way can those weird elements sorted?" Answer: Yes!

  • Default User Avatar

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

  • Default User Avatar

    Hello, if the "Gotcha" topic I mentioned doesn't trigger you, then it looks like you're not affected by it either.
    Otherwise, I have described as briefly as I could what it is about.
    For the rant in it i apologize again, but sometimes this must also be said

  • Custom User Avatar

    It seems to me that you have made an assumption that we know what you are talking about, but I should point out that's not the case. What exactly you want?

  • Default User Avatar

    Just the other day I read here on Codewars from someone who complained about so-called "Gotcha" Katas.
    This is one of them.
    I am beginning to understand this very well!
    Just, why??
    Why can't you write in the description the actual, or better, the complete problem?
    is this really such an uplifting "hihihihi" moment?

    Why not put one of the more complex inputs - at least just ONE - in the test section too, rather than "Gotcha!" at Attempt first.

    sry for the rant - have a nice weekend everyone!

  • Default User Avatar

    definately not a 6kyu - if you compare solutions of this and other 6kyu's ...

  • Custom User Avatar

    Approved! ;)

  • Loading more items...