#K54492. Detecting Palindrome Substrings in a Grid
Detecting Palindrome Substrings in a Grid
Detecting Palindrome Substrings in a Grid
You are given a grid of characters with \( n \) rows and \( m \) columns. Your task is to determine if there exists any contiguous substring in any row or column that is a palindrome of length at least 2. A string \( s \) is called a palindrome if \( s = s^R \), i.e., it reads the same forward and backward.
If such a substring exists, output YES
, otherwise output NO
.
inputFormat
The first line of input contains an integer \( T \), the number of test cases. Each test case consists of:
- A line with two integers \( n \) and \( m \), representing the number of rows and columns respectively.
- \( n \) lines, each containing a string of length \( m \) representing a row of the grid.
outputFormat
For each test case, print a single line with YES
if there exists any contiguous palindrome substring in any row or column, otherwise print NO
.
1
3 3
abc
aba
xyz
YES
</p>