Print all possible paths from top left to bottom right of a mXn matrix | C # program to Print all possible paths from top left to bottom right of a mXn matrix ; If we reach the bottom of maze , we can only move right ; path . append ( maze [ i ] [ k ] ) ; If we hit this block , it means one path is completed . Add it to paths list and print ; If we reach to the right most corner , we can only move down ; path . append ( maze [ j ] [ k ] ) If we hit this block , it means one path is completed . Add it to paths list and print ; Add current element to the path list path . append ( maze [ i ] [ j ] ) ; Move down in y direction and call findPathsUtil recursively ; Move down in y direction and call findPathsUtil recursively ;  ; Driver code
using System ; using System . Collections . Generic ; class GFG { static List < List < int > > allPaths = new List < List < int > > ( ) ; static void findPathsUtil ( List < List < int > > maze , int m , int n , int i , int j , List < int > path , int indx ) { if ( i == m - 1 ) { for ( int k = j ; k < n ; k ++ ) { path [ indx + k - j ] = maze [ i ] [ k ] ; } Console . Write ( " [ " + path [ 0 ] + " , ▁ " ) ; for ( int z = 1 ; z < path . Count - 1 ; z ++ ) { Console . Write ( path [ z ] + " , ▁ " ) ; } Console . WriteLine ( path [ path . Count - 1 ] + " ] " ) ; allPaths . Add ( path ) ; return ; } if ( j == n - 1 ) { for ( int k = i ; k < m ; k ++ ) { path [ indx + k - i ] = maze [ k ] [ j ] ; } Console . Write ( " [ " + path [ 0 ] + " , ▁ " ) ; for ( int z = 1 ; z < path . Count - 1 ; z ++ ) { Console . Write ( path [ z ] + " , ▁ " ) ; } Console . WriteLine ( path [ path . Count - 1 ] + " ] " ) ; allPaths . Add ( path ) ; return ; } path [ indx ] = maze [ i ] [ j ] ; findPathsUtil ( maze , m , n , i + 1 , j , path , indx + 1 ) ; findPathsUtil ( maze , m , n , i , j + 1 , path , indx + 1 ) ; } static void findPaths ( List < List < int > > maze , int m , int n ) { List < int > path = new List < int > ( ) ; for ( int i = 0 ; i < m + n - 1 ; i ++ ) { path . Add ( 0 ) ; } findPathsUtil ( maze , m , n , 0 , 0 , path , 0 ) ; } static void Main ( ) { List < List < int > > maze = new List < List < int > > ( ) ; maze . Add ( new List < int > { 1 , 2 , 3 } ) ; maze . Add ( new List < int > { 4 , 5 , 6 } ) ; maze . Add ( new List < int > { 7 , 8 , 9 } ) ; findPaths ( maze , 3 , 3 ) ; } }