Minimum jumps to traverse all integers in range [ 1 , N ] such that integer i can jump i steps | Utility function to find minimum steps ; Initialize count and result ; Traverse over the range [ 1 , N ] ; Update res ; Increment count ; Return res ; Input ; Function call
function minSteps ( N ) { let count = 1 , res = 0 ; for ( let i = 1 ; i <= N ; i += count ) { res = Math . max ( res , count ) ; count ++ ; } return res ; } let N = 6 ; document . write ( minSteps ( N ) ) ;