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 ; Driver code ; Input integer ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; int minSteps ( int N ) { int res = ( sqrt ( 1 + 8 * N ) - 1 ) / 2 ; return res ; } int main ( ) { int N = 6 ; cout << minSteps ( N ) << " STRNEWLINE " ; }