Print all ways to reach the Nth stair with the jump of 1 or 2 units at a time | C # program for the above approach ; 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
using System ; using System . Collections . Generic ; class GFG { static List < string > TotalPossibleJumps ( int N ) { if ( ( N - 1 ) == 0 ) { List < string > newvec = new List < string > ( ) ; newvec . Add ( " " ) ; return newvec ; } else { if ( N < 0 ) { List < string > newvec = new List < string > ( ) ; return newvec ; } } List < string > jump1 = TotalPossibleJumps ( N - 1 ) ; List < string > jump2 = TotalPossibleJumps ( N - 2 ) ; List < string > totaljumps = new List < string > ( ) ; foreach ( string s in jump1 ) { totaljumps . Add ( "1" + s ) ; } foreach ( string s in jump2 ) { totaljumps . Add ( "2" + s ) ; } return totaljumps ; } public static void Main ( ) { int N = 3 ; List < string > Ans = TotalPossibleJumps ( N ) ; foreach ( string it in Ans ) Console . WriteLine ( it ) ; } }