Ad
  • Custom User Avatar

    your code still doesn't handles cases with arr[0]==arr[1] (you can try this with the example input [18, 18, 10, -3, -4, 15, 15, -1, 13, 17, 11, 4, 18, -4, 19, 4, 18, 10, -4, 8, 13, 9, 16, 18, 6, 7]

    a fixed test has been added with the very same example

    tag these kinds of comments with suggestions/question. issue tags are used when there is a bug with the kata, where this is a problem with your code

  • Custom User Avatar

    thank you @hobovsky

  • Custom User Avatar

    your first approach is not good enough because its complexity is not sufficient. you need something better than O(n). The second approach is O(1) (kinda) and would be ok if you had decimal numbers with a veeeeeeeeery large precision at your disposal. 1024 bits of precision is not enough for numbers with thousands of digits.

    you need to find an algorithm which is better than linear complexity, and uses precise numbers thorough all calculations.

  • Custom User Avatar

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

  • Custom User Avatar

    OP solved it, closing

  • Custom User Avatar

    @FArekkusu thanks, now i see where the problem is

  • Custom User Avatar

    my code works fine with python 3.8

    No, your code works with your tests. If you called your function with the same inputs as the ones tested here, it would raise the same exception(s). You already see which input causes your function to fail - now try actually debugging it.

  • Custom User Avatar

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

  • Custom User Avatar

    The first version of my code passed all tests and was submitted but got an error when arr[0] == arr[1]. This was evident when the random tests put the same value for both indexes. The initial fixed tests should include a test to check it. My code was not right because it included as a peak the value of arr[1] when arr [0] == arr [1], and in this case, arr[1] cannot be a peak.

  • Custom User Avatar

    It was my mistake, I did not consider cleaning the vars before sending the return, and being global they also kept the values of the previous tests.

  • Custom User Avatar

    There might be something wrong with the random tests in php.

    I pass all tests except random, where I get a timeout (over 12000 ms), using my code elsewhere (online php sandbox) on a random array with 95 peaks, looped 100 times, results in: "Total execution time in seconds: 0.085011005401611". I have a for loop which contains two very short foreach loops for the before and after arrays. Both have breaks and the second does not get used if the first fails. There doesn't seem to be anything to optimise out.

    Logging to STDOUT, it seems that the random test fails at 293 arrays being generated, but without any of them actually passing through the function (I get 293 '1's and no arrays using fwrite(STDOUT, print_r($arr)); before my timeout, while passed tests give me one '1' per array, then the actual arrays are printed, as expected).

  • Custom User Avatar

    Make them local inside pick_peaks and pass them as arguments to the other function, in theory, that would work.

  • Custom User Avatar

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

  • Custom User Avatar

    Make your global vars local.

  • Custom User Avatar

    I am having a problem with the use of global variables, out the box my code works correctly, but here in the tests, it fails flat out in all the tests. I have tested with different versions of python and in all of them, it works correctly.

    [spellmell@nexus codewars]$ python3.8 15_pick_peaks.py
    [7, 9, 5, 0, 7, 9, 9, 8, 6]
    pos:[1, 5]
    peaks:[9, 9]
    python 3.8.12 (default, Aug 30 2021, 00:00:00)
    [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]

    [spellmell@nexus codewars]$ python3.9 15_pick_peaks.py
    [7, 8, 9, 5, 4, 0, 4, 2, 3]
    pos:[2, 6]
    peaks:[9, 4]
    python 3.9.9 (main, Nov 19 2021, 00:00:00)
    [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)]

    [spellmell@nexus codewars]$ python3.10 15_pick_peaks.py
    [6, 1, 0, 3, 4, 8, 7, 2, 8]
    pos:[5]
    peaks:[8]
    python 3.10.1 (main, Dec 7 2021, 00:00:00) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)]

    Here: Time: 500ms Passed: 0 Failed: 10 Exit Code: 1

    It is confirmed that the problem is the global variables, when removing them the code works.
    I was reading the "troubleshooting" page, and I see that there is some reference to the problem, but
    I can't understand. Any suggestions on how I can solve it?

  • Loading more items...