✅Grid Magic (Contest)
Grid Magic (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
Problem Statement :
You are given a square character grid of side length N (where N is odd). You have to find whether the given grid is magical or not. A grid is said to be magical if it contains the same character on each element in its diagonal. Moreover, all the elements that are not present on the diagonal have to have the same character (which is different than the one on the diagonal). Input The first line contains integer N. Each of the next N lines contain N lowercase English latin characters.
Constraints: 3 <= N <= 500 N is odd. Output Print "YES" if the given grid is magical, else print "NO", without the quotes. Example Sample Input: 3 aba bab aba
Sample Output: YES
Explaination: All characters on its diagonal are the same. All the characters other than the diagonal are same. The characters on the diagonal and the rest of the grid do not match. Thus, it is a magical grid.
link:https://my.newtonschool.co/playground/code/slbujc4wklc7
Last updated