Given an N x M matrix of integers, the task is to count the number of palindromic pluses in the array.
Palindromic plus is formed when a palindromic sub-row and palindromic sub-column cross each other at the middle element.
Input: matrix = [[1, 2, 1], [2, 3, 2], [3, 2, 1]]
Palindromic row from (1, 0) – > (1, 2) and Palindromic column (0, 1) -> (2, 1) form a palindromic plus.
Input: matrix = [[1, 2, 1, 3], [2, 3, 2, 3], [3, 2, 1, 4]
The palindromic pluses in the given matrix are:
To solve the problem, follow the steps below:
- Traverse all the cells that can be the center of a palindromic plus, that is, all the cells apart from the ones belonging to the first and last row and columns.
- For all these cells (i, j), check if a[i][j – 1] is equal to a[i][j + 1] and a[i – 1][j] is equal to a[i + 1][j]. If both the conditions satisfies, then increase the count of palindromic pluses.
- Print the final count of palindromic pluses.
Below is the implementation of the above approach:
Time Complexity: O(N2)
Auxiliary Space: O(1)
- Minimum steps to convert all paths in matrix from top left to bottom right as palindromic paths
- Minimum steps to convert all paths in matrix from top left to bottom right as palindromic paths | Set 2
- Number of palindromic paths in a matrix
- Print all palindromic paths from top left to bottom right in a matrix
- Count all possible paths from top left to bottom right of a mXn matrix
- Count of odd length contiguous Palindromic sequences in a Matrix
- Maths behind number of paths in matrix problem
- Print all possible paths from top left to bottom right of a mXn matrix
- Sum of cost of all paths to reach a given cell in a Matrix
- Total number of decreasing paths in a matrix
- Paths from entry to exit in matrix and maximum path sum
- Print all paths from top left to bottom right in a matrix with four moves allowed
- Minimum steps to convert all top left to bottom right paths in Matrix as palindrome | Set 2
- Count of Fibonacci paths in a Binary tree
- Count of paths in given Binary Tree with odd bitwise AND for Q queries
- Count palindromic characteristics of a String
- Count All Palindromic Subsequence in a given String
- Count of root to leaf paths whose permutation is palindrome in a Binary Tree
- Count all Prime Length Palindromic Substrings
- Count of K-size substrings having palindromic permutations
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.