#K95277. Palindromic Path in a Grid
Palindromic Path in a Grid
Palindromic Path in a Grid
You are given a grid of size ( n \times n ) where each cell contains a lowercase English letter. Your task is to determine whether there exists a path from the top-left corner to the bottom-right corner such that the concatenated string of characters along the path forms a palindrome. You are only allowed to move either right or down at any step. A string is a palindrome if it reads the same forwards and backwards.
inputFormat
The first line contains an integer ( n ) (1 ≤ n ≤ 10), representing the size of the grid. The next ( n ) lines each contain a string of length ( n ), representing the rows of the grid.
outputFormat
Output a single line containing either "YES" if there exists at least one palindromic path from the top-left to the bottom-right, or "NO" if no such path exists.## sample
3
aba
bcb
aba
YES