Ad
  • Custom User Avatar

    I think I know what method you are using. If it is the one I am thinking of, then if there are no results then null is returned. You are calling length method on null, which leads to your error.

  • Custom User Avatar

    You don't even need to filter the whole array, just the first 3 numbers.

  • Custom User Avatar

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

  • Custom User Avatar

    Also wondering this, because I can't run his code on my IDLE (Python 3.6) since it gives me either an AttributeError or ValueError depending on None, num, or alphanumeric input.

  • Custom User Avatar

    I feel that there is only one true answer (at least in Python) since at least one of the test case has a ridiculously large n value.
    So if anyone is stuck, your answer must be O(1). Luckily, I remembered that I did this problem in my algorithm course.

  • Custom User Avatar

    I was also stumped, but re-read instructions and it's probably related to:

    Also, beware of plateaus !!! [1, 2, 2, 2, 1] has a peak while [1, 2, 2, 2, 3] does not.

    So imagine you are working with an arr like [1, 2, 2, 2, 3, 3], where the second to last number (the first 3) is giving you a false positive.

    Edit: and also imagine if you are working with double plateaus such as [1, 2, 2, 3, 3, 1]. In this case, the peak should be the first 3, but it's possible that the first 2 is giving you a false positive resulting in 2 peaks, when there should only be 1 in this case.

    Hopefully final edit: I created a test scenario which your code might not pass according to your errors: [1,1,2,2,3,5,5,5,3,3,3,1,2,3]. There should only be 1 peak, but your code might give 2. Just passed this, so hopefully this helps.

  • Custom User Avatar

    Great example which emphasizes how concise ES6 can be compared to older ES versions, such as the top answer for this kata.