Ad
  • Custom User Avatar

    Really nice kata on algorithms optimization and dynamic programming to exercise with.

  • Custom User Avatar

    Thanks! Yes, I found O(n) solution and passed tests successfully

  • Custom User Avatar

    Great, I'm glad it makes sense. Good luck!

  • Custom User Avatar

    Thanks for the replies mozkomor, sorry I didn't see your first reply it never notified me.

    Your explanation makes sense to me. I think the wording just tripped me up and I thought there would be subarrays given to us.

    Thanks!

  • Custom User Avatar

    The final tests contain 50 tests with ~1k elements and 10 tests with ~20m elements. Make sure you can pass all within the timeframe of your language.

  • Custom User Avatar

    That is not right, as your path starts at the montain of height 1 and ends at the mountain of height 6, so energy it took is at least 6 - 1 = 5. Energy constain in my example is E = 3.

  • Custom User Avatar

    I think the longest mountain pass in your example is [1,2,3,4,6,6] so the answer should be (6,2), because 5=(2-1)+(3-2)+(4-3)+(6-4)+(6-6). No?

  • Custom User Avatar

    Hi! There is a solution with O(n) time complexity. Good luck!

  • Custom User Avatar

    Hi! When I try to attempt Java17 solution I get exception "Timed Out (16000 ms)" in randomTests. My solution has O(n* n) and I optomized it with multithreading. That give me speed about 11 sec on local mashine with array of 10000000 size. Is there any better solution? Or is it problem with codewars server?

  • Custom User Avatar

    From the Problem Description section: You start at any initial index of your choice..

    Consider the first mountain as the start.

  • Custom User Avatar

    The sample tests seem to imply that climbing the first mountain costs no energy. This seems odd. Don't we start at height 0?

  • Custom User Avatar

    You are given a mountain range (an array of mountain heights) and your task is to find the longest mountain pass (the longest subarray given the energy constrain).

    For example, for a given energy constrain E = 3 and a given mountain range = [2, 5, 1, 2, 3, 4, 6, 6] the longest mountain pass you can take is [5, 1, 2, 3, 4], which has length 5. You would return the tuple (5, 1).

  • Custom User Avatar

    I'm having trouble understanding the mountain pass subarray. Are we given it?

    I'm particularly confused by this:
    "A mountain pass is defined as a subarray of the mountain array. The length of a mountain pass is the length of the subarray."

  • Custom User Avatar

    That would be great. looking forward to it.

  • Custom User Avatar

    time to approve now?

  • Loading more items...