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.

  • 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?

  • Custom User Avatar
  • Custom User Avatar

    Yeah, generating that output is overdoing it mightily. That must have been quite a lot of work!

    You're welcome. ^^

  • Custom User Avatar

    Yes. It's that simple.

    @return {number} max profit
    

    I always thought warnings like "do not include the quotes" were superfluous. :/

  • Custom User Avatar

    You are returning '=> 15 (buy at 1, 2, 3, 4, 5 and then sell all at 6)'.

    YOU MUST RETURN A NUMBER.

  • Custom User Avatar

    You are not returning a string, are you? You have to return a number.

    What is the complete, exact text of the failure message?

  • Custom User Avatar

    yes. @rowcased is correct.

  • Default User Avatar

    '.... .... . ..... .... ... .... .... '

    '.... .... . ..... .... ... .... ....'

    it's hard to see, but yours have a trailing whitespace

  • Custom User Avatar

    The numbers of interest are all the number between 0 and n which squared contain at least one digit d. Is it clearer now? And no, they're not passed to you in any way, you have to get them for yourself.

  • Custom User Avatar

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

  • Custom User Avatar

    Just a year at codewars and nothing else.)) 1-2 cata per day