Hackerrank | Jumping cloud revisited

Explanation:

  • Infinite loop    
  • Initialise energy as 100
  • Energy decreases depending on c[i]
                If c[i] == 0
                    e = e -1 - 0
                else:
                    e -= 1 - 2(1)



def jumpingOnClouds(c, k):
    e =100
    i = 0
    while(True):
        e = e - 1 -(2 * c[i])
        i = (i + k) % n
        if i == 0:
            break

    return e

Comments

Popular posts from this blog

Hackerrank | Sequence Equation

HackerRank | Organizing Containers of Balls

HackerRank | Minimum Distances