Print all ways to reach the Nth stair with the jump of 1 or 2 units at a time | Function to find all the ways to reach Nth stair using one or two jumps ; Base Cases ; Recur for jump1 and jump2 ; Stores the total possible jumps ; Add "1" with every element present in jump1 ; Add "2" with every element present in jump2 ; Driver Code
const TotalPossibleJumps = ( N ) => { if ( ( N - 1 ) == 0 ) { let newvec = [ ] ; newvec . push ( " " ) ; return newvec ; } else { if ( N < 0 ) { let newvec = [ ] ; return newvec ; } } let jump1 = TotalPossibleJumps ( N - 1 ) ; let jump2 = TotalPossibleJumps ( N - 2 ) ; let totaljumps = [ ] ; for ( let s in jump1 ) { totaljumps . push ( " " + jump1 [ s ] ) ; } for ( let s in jump2 ) { totaljumps . push ( " " + jump2 [ s ] ) ; } return totaljumps ; } let N = 3 ; let Ans = TotalPossibleJumps ( N ) ; for ( let it in Ans ) document . write ( ` ${ Ans [ it ] } ` ) ;