Minimum jumps to traverse all integers in range [ 1 , N ] such that integer i can jump i steps | C ++ implementation of 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minSteps ( int N ) { int count = 1 , res = 0 ; for ( int i = 1 ; i <= N ; i += count ) { res = max ( res , count ) ; count ++ ; } return res ; } int main ( ) { int N = 6 ; cout << minSteps ( N ) << " STRNEWLINE " ; }