#K44092. Tile Arrangement
Tile Arrangement
Tile Arrangement
You are given a collection of tile rows, each represented by a string of lowercase letters. Each character in the string represents a colored tile. Your task is to verify whether an arrangement of these tile rows satisfies the condition that no two adjacent rows have tiles of the same color in the same column. In other words, given rows, for every adjacent pair of rows (row and row ) and for every column index , the condition
[
tile[i][j] \neq tile[i+1][j]
]
must hold.
The input will contain multiple test cases. For each test case, the first line contains an integer representing the number of rows. This is followed by lines, each containing a string. A test case with indicates the end of input. For each test case, output "YES" if the arrangement satisfies the condition, or "NO" otherwise.
inputFormat
The input consists of multiple test cases. Each test case begins with a line containing an integer () indicating the number of tile rows. It is followed by lines, each containing a string representing a row of tiles. The input terminates with a line containing a single zero (0), which should not be processed.
outputFormat
For each test case, output a single line containing either "YES" if the arrangement is valid, or "NO" if it is not.## sample
3
abc
def
ghi
0
YES
</p>