Jumping on the Clouds: Revisited

  • + 0 comments

    Here is my Python solution! We use a while loop to continually jump k steps forward and subtract the correct amount from the energy.

    def jumpingOnClouds(c, k):
        n = len(c)
        e = 100
        index = 0
        while True:
            index = (index + k) % n
            e -= 1
            if c[index] == 1:
                e -= 2
            if index == 0:
                return e