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.

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值