6 kyu

Frog jumping

1,228 of 2,862alex.budiakov

Description:

Help the frog to find a way to freedom


You have an array of integers and have a frog at the first position

[Frog, int, int, int, ..., int]

The integer itself may tell you the length and the direction of the jump

For instance:
 2 = jump two indices to the right
-3 = jump three indices to the left
 0 = stay at the same position

Your objective is to find how many jumps are needed to jump out of the array.

Return -1 if Frog can't jump out of the array

Example:
array = [1, 2, 1, 5]; 
jumps = 3  (1 -> 2 -> 5 -> <jump out>)

All tests for this Kata are randomly generated.

Fundamentals
Arrays
Algorithms

More By Author:

Check out these other kata created by alex.budiakov

Stats:

CreatedMay 6, 2014
PublishedMay 6, 2014
Warriors Trained6827
Total Skips613
Total Code Submissions22594
Total Times Completed2862
JavaScript Completions1228
Java Completions722
Python Completions860
CoffeeScript Completions20
Ruby Completions87
Factor Completions6
C Completions44
D Completions6
Total Stars129
% of votes with a positive feedback rating94% of 459
Total "Very Satisfied" Votes407
Total "Somewhat Satisfied" Votes47
Total "Not Satisfied" Votes5
Ad
Contributors
  • alex.budiakov Avatar
  • jhoffner Avatar
  • adrian.eyre Avatar
  • Voile Avatar
  • NunoOliveira Avatar
  • FArekkusu Avatar
  • RobsonMoon Avatar
  • trashy_incel Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • razetime Avatar
Ad