• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
May 19, 2023 |2.8K Views
Print all palindromic paths from top left to bottom right in a matrix
  Share   Like
Description
Discussion

This video discusses the problem in which we are given a matrix containing lower alphabetical characters only, we need to print all palindromic paths in given matrix. A path is defined as a sequence of cells starting from top-left cell and ending at bottom-right cell. We are allowed to move to right and down only from current cell. We cannot go down diagonally. 

For example: 

Input : mat[][] = {"aaab”, 
                           "baaa”
                           “abba”}
Output : aaaaaa, aaaaaa, abaaba

Explanation :

  • aaaaaa:  (0, 0) -> (0, 1) -> (1, 1) -> 
         (1, 2) -> (1, 3) -> (2, 3)    
  • aaaaaa: (0, 0) -> (0, 1) -> (0, 2) -> 
         (1, 2) -> (1, 3) -> (2, 3)    
  • abaaba: (0, 0) -> (1, 0) -> (1, 1) -> 
         (1, 2) -> (2, 2) -> (2, 3)

Checkout, the video for the complete explanation with implementation.

Article: https://www.geeksforgeeks.org/print-palindromic-paths-top-left-bottom-right-matrix/
SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More