Jumping On The Clouds – HackerRank Challenge

Tue May 28 2019

There are several way to solve this, but we want to have most efficient and easy to understand. Thats why I always mention to start your coding and problem solving on paper. Our code editors can wait This is the exercise link Check out the video I posted describing my solution:

and the code of course:
func jumpingOnClouds(c []int32) int32 {
    var jumps int32
    cidx := 0
    eidx := len(c) - 1
    for {
        if cidx == eidx {
            return jumps
        }
        twoStepIdx := cidx + 2
        cidx++
        if twoStepIdx <= eidx && c[twoStepIdx] == 0 {
            cidx++
        }
        jumps++
    }
}