• + 0 comments

    Guys, this is a math problem. The solution lies in understanding that it's just walks and jumps. The solution can be defined as: floor((n+walks)/2), where n is the total number of clouds. A walk in this case represents a forced walk (when there is an even number of clouds between two consecutive thunderclouds)

    My solution in python:

    def jumpingOnClouds(c):
        # Write your code here
        n = len(c)
        walks = 0
        last_thunderhead = -1
        for i in range(n):
            if c[i]:
                if (i - last_thunderhead)%2:
                    walks += 1
                last_thunderhead = i
        return math.floor((n + walks)/2)