Minimum jumps to traverse all integers in range [ 1 , N ] such that integer i can jump i steps | Java program for the above approach ; Utility function to find minimum steps ; Initialize count and result ; Traverse over the range [ 1 , N ] ; Update res ; Increment count ; Return res ; Driver Code ; Input ; Function call
import java . io . * ; class GFG { static int minSteps ( int N ) { int count = 1 , res = 0 ; for ( int i = 1 ; i <= N ; i += count ) { res = Math . max ( res , count ) ; count ++ ; } return res ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . println ( minSteps ( N ) ) ; } }