coding task: array jump back

requirement :
use c++ to do the function "int ArrayChallenge(int arr[], int arrLength)" :
1. numbers stored in arr[].
2. the function first determine the largest element in the array, 
3. then you can move to left or right in the arr[] with arr[currentindex], you can looping around the arr.
4. continuously according to integer in the current index. 
5. If you can reach the same spot within the array, then the function should return the least amount of jumps it took. 
7. For example: if the input is [2, 3, 5, 6, 1] you'll start at the spot where 6 is and if you jump 6 spaces to the right while looping around the array you end up at the last element where the 1 is. Then from here you can jump 1 space to the left and you're back where you started, so your program should output 2. 
8.If it's impossible to end up back at the largest element in the array your program should output -1. 
9. The largest element in the array will never equal the number of elements in the array. 
10. The largest element is unique.

Examples
Input: {1,2,3,4,2}
Output: 3
Input: {1,7,1,1,1,1}
Output: 2

code :

TBD.

你可能感兴趣的:(coding)