grid of positive integers. Consider its two diagonals: the main one, cells grid[i][i], and the anti-diagonal, cells grid[i][n - 1 - i].
Return the largest prime number found on at least one of the diagonals. If neither diagonal holds a prime, return 0.
A prime is greater than 1 and divisible only by 1 and itself.grid=[[7, 4, 9], [6, 8, 2], [13, 5, 10]] → 13
The diagonals hold 7, 8, 10, 9 and 13. Of these, 7 and 13 are prime, and the larger is 13.
grid=[[4, 3], [5, 1]] → 5
In a 2×2 grid the main diagonal holds 4 and 1, the other one holds 3 and 5. The answer is 5.
grid=[[1, 2], [3, 9]] → 3
The primes 2 and 3 sit on the anti-diagonal, so the answer is 3. Had the diagonals held only 1 and 9, the answer would be 0.
grid=[[7, 4, 9], [6, 8, 2], [13, 5, 10]]
13
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.