• + 0 comments

    With Python 3:

    Solution 1:

    def jumpingOnClouds(c):
        val = 0
        steps = 0
        
        while val < len(c) - 1:
            if val + 3 <= len(c) and (c[val + 1] == 1 or c[val + 2] == 0 or c[val + 3] == 1):
                val += 2
            else:
                val += 1
            steps += 1
        
        return steps
    

    Solution 2:

    def jumpingOnClouds(c):
        val = 0
        steps = 0
        
        while val < len(c) - 1:
            val = val + 2 if (val + 3 <= len(c) and (c[val + 1] == 1 or c[val + 2] == 0 or c[val + 3] == 1)) else val + 1
            steps += 1
        
        return steps