50 cases Time limit 1000 ms total Memory 256 MB
A kangaroo is crossing a river on a line of stepping stones. Each stone has a number painted on it. The kangaroo starts on the first stone, and each hop takes it forward by the number on the stone it's standing on. Once it hops past the last stone, it's across.
Return how many hops it takes to get across, or -1 if it lands on a 0 and gets
stuck.
Constraints:
len(stones) ≤ 15Examples:
f([1, 2, 0, 3]) returns 3 (stones 0, 1 and 3, then off the end)
f([3, 1, 1]) returns 1
f([2, 1, 1, 0]) returns -1 (it lands on the last stone, which is 0)
f([10]) returns 1
[[1, 2, 0, 3]]
3
[[3, 1, 1]]
1
[[2, 1, 1, 0]]
-1
[[10]]
1