A remote research outpost arranges its solar-powered relay towers in a perfect square grid with n rows and n columns, indexed 0 through n-1 along each axis. Every tower reports an integer signal strength for the current hour. Outpost protocol permits exactly one active surveillance pattern, called the sentinel cross: every tower sitting on the main diagonal (where its row index equals its column index) or on the anti-diagonal (where its row index plus its column index equals n-1) must be transmitting a nonzero signal, and every other tower must be completely silent, reporting a signal of exactly zero. Given this hour's grid of readings, determine whether the sentinel cross protocol currently holds.
Print a single line containing true if every diagonal or anti-diagonal tower has a nonzero reading and every other tower reads exactly 0, or false otherwise.
Example 1
Input
4 5 0 0 3 0 -2 6 0 0 7 4 0 9 0 0 1
Expected
true
Explanation
n=4. The main-diagonal cells (0,0)=5, (1,1)=-2, (2,2)=4, (3,3)=1 and the anti-diagonal cells (0,3)=3, (1,2)=6, (2,1)=7, (3,0)=9 are all nonzero, and every remaining cell is exactly 0, so the sentinel cross protocol holds and the answer is true.
Example 2
Input
3 1 7 2 0 3 0 4 0 5
Expected
false
Explanation
n=3. Cell (0,1) is not on either diagonal (0 != 1 and 0+1 != 2), yet it reads 7 instead of 0, breaking the requirement that every non-diagonal tower stay silent, so the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →