Assume an array of numbers . Initially you are standing on the very first number, say '4'. Now jump 4 steps forward (till number '0'). Now you are standing on ZERO hence just step to the next number '3' (doing this is NOT a jump) then jump 3 steps again, you've reached number '6', finally you'll jump 6 steps forward to be out of the array. Collectively, you needed to jump thrice.
How many times do you need to jump in this case?
Details and Assumptions:
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Interesting question. The size of the array required using an external file to speed up program speed. My method simply checked if each position with value x in the array was not 0, and jumped to the space x in front (in the array). If the value was zero, it would jump to the next value, but not count it as a jump.