#K53652. Minimum Number of Jumps
Minimum Number of Jumps
Minimum Number of Jumps
You are given an array of non-negative integers A where each element of the array represents the maximum number of steps you can jump forward from that position. Your task is to determine the minimum number of jumps required to reach the final index of the array starting from the first index. If the end is not reachable, print inf
(representing infinity).
The problem can be formulated as follows:
Given an array \( A = [a_0, a_1, \dots, a_{n-1}] \), find the minimum number of jumps to reach \( a_{n-1} \) starting from \( a_0 \). At each position \( i \), you can jump to any position \( j \) such that \( i 1 \), then the end cannot be reached.
inputFormat
The first line contains an integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers which denote the array \( A \).
outputFormat
Print an integer representing the minimum number of jumps required to reach the end of the array. If the final index is not reachable, print inf
.
5
2 3 1 1 4
2
</p>