[Huawei OD test questions] Minimum number of steps (java) 100% pass rate [2023 (B volume) 100 points]

Minimum number of steps

topic description

An array of positive integers, set nums
to a maximum of 100 members
Find the minimum number of steps taken from the first member to the last member of the array

Require:

The first step must start from the first element, and 1 <= step length of the first step < len / 2 (len is the length of the array).
From the second step, only the corresponding number of steps can be taken with the number of the member, not more No less, if the target is unreachable, return -1, and only output the minimum number of steps
Can only go to the end of the array and not back

enter description

An array of positive integers, elements separated by spaces
Array length < 100

output description

Positive integer, the minimum number of steps
does not exist output -1

example one

enter

7 5 9 4 2 6 8 3 5 4 3 

Guess you like

Origin blog.csdn.net/weixin_45541762/article/details/132459937