Print all palindromic paths from top left to bottom right in a matrix | Javascript program to print all palindromic paths from top left to bottom right in a grid . ; i and j are row and column indexes of current cell ( initially these are 0 and 0 ) . ; If we have not reached bottom right corner , keep exlporing ; If we reach bottom right corner , we check if if the path used is palindrome or not . ; Driver code
function isPalin ( str ) { let len = str . length / 2 ; for ( let i = 0 ; i < len ; i ++ ) { if ( str [ i ] != str [ str . length - i - 1 ] ) return false ; } return true ; } function palindromicPath ( str , a , i , j , m , n ) { if ( j < m - 1 i < n - 1 ) { if ( i < n - 1 ) palindromicPath ( str + a [ i ] [ j ] , a , i + 1 , j , m , n ) ; if ( j < m - 1 ) palindromicPath ( str + a [ i ] [ j ] , a , i , j + 1 , m , n ) ; } else { str = str + a [ n - 1 ] [ m - 1 ] ; if ( isPalin ( str ) ) document . write ( str + " " ) ; } } let arr = [ [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] , [ ' ' , ' ' , ' ' , ' ' ] ] let str = " " palindromicPath ( str , arr , 0 , 0 , 4 , 3 )