Given a matrix containing lower alphabetical characters only, we need to find 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. You cannot go down diagonally.
Input : mat[][] = {"aaab”,
"baaa”
“abba”}
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)
Output = {"aaaaaa","aaaaaa","abaaba"}
Order of elements in the output array doesn't matter.
Your Answer.java should implement following interface.
public String[] findPalindromicPaths(String[] input) {
return null;
}
Answer
Answer
No comments:
Post a Comment