human
Minimum number of jumps to reach end | Returns Minimum number of jumps to reach end.
jumps [ 0 ] will hold the result.
Start from the second element , move from right to left and construct the jumps [ ] array where jumps [ i ] represents minimum number of jumps needed to reach arr [ m - 1 ] form arr [ i ].
If arr [ i ] is 0 then arr [ n - 1 ] can 't be reached from here.
If we can directly reach to the end point from here then jumps [ i ] is 1.
Otherwise , to find out the minimum number of jumps needed to reach arr [ n - 1 ] , check all the points reachable from here and jumps [ ] value for those points.
initialize min value.
following loop checks with all reachavle points and takes the minimum.
Handle overflow.
or INT_MAX.
Driver program to test above function"
Solution in Python:
 ... Can you provide a code to minimum number of jumps to reach end and the other steps required?
assistant
#Here is code to minimum number of jumps to reach end and the other steps required.
 def minJumps ( arr , n ) :
	jumps = [ 0 for i in range ( n ) ]
	for i in range ( n - 2 , - 1 , - 1 ) :
		if ( arr [ i ] == 0 ) :
			jumps [ i ] = float ( ' inf ' )
		elif ( arr [ i ] >= n - i - 1 ) :
			jumps [ i ] = 1
		else :
			min = float ( ' inf ' )
			for j in range ( i + 1 , n ) :
				if ( j <= arr [ i ] + i ) :
					if ( min > jumps [ j ] ) :
						min = jumps [ j ]
			if ( min != float ( ' inf ' ) ) :
				jumps [ i ] = min + 1
			else :
				jumps [ i ] = min
	return jumps [ 0 ]
arr = [ 1 , 3 , 6 , 3 , 2 , 3 , 6 , 8 , 9 , 5 ]
n = len ( arr )
print ( ' Minimum ▁ number ▁ of ▁ jumps ▁ to ▁ reach ' , ' end ▁ is ' , minJumps ( arr , n - 1 ) )