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
def TotalPossibleJumps ( N ) : NEW_LINE INDENT if ( ( N - 1 ) == 0 ) : NEW_LINE INDENT newvec = [ ] NEW_LINE newvec . append ( " " ) NEW_LINE return newvec NEW_LINE DEDENT else : NEW_LINE INDENT if ( N < 0 ) : NEW_LINE INDENT newvec = [ ] NEW_LINE return newvec NEW_LINE DEDENT DEDENT jump1 = TotalPossibleJumps ( N - 1 ) NEW_LINE jump2 = TotalPossibleJumps ( N - 2 ) NEW_LINE totaljumps = [ ] NEW_LINE for s in jump1 : NEW_LINE INDENT totaljumps . append ( "1" + s ) NEW_LINE DEDENT for s in jump2 : NEW_LINE INDENT totaljumps . append ( "2" + s ) NEW_LINE DEDENT return totaljumps NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 3 NEW_LINE Ans = TotalPossibleJumps ( N ) NEW_LINE for it in Ans : NEW_LINE INDENT print ( it ) NEW_LINE DEDENT DEDENT