Back
Close

The king of the hill

Statement

 Goal

For a given matrix of integers find the highest value such that all its adjacent (NSWE) values are strictly lower. Values on the edges of matrix are never a valid answer (they do not have all four neighbors required).
Input
Line 1: Integers R C being the numbers of, accordingly, rows and columns of the matrix.
Next R lines: C space separated integers.
Output
One integer K, which is the highest matrix value such that its four adjacent neighbors are strictly lower, or -666 if such value does not exist.
Constraints
3 ≤ R, C ≤ 100
-100 ≤ K ≤ 100
Example
Input
3 3
1 2 2
1 3 1
2 2 1
Output
3

Game modes
Fastest, Shortest

Test cases
Simple case Test
Input
3 3 1 2 2 1 3 1 2 2 1
Output
3

Validator 1 Validator
Input
3 3 2 2 2 4 99 5 1 7 -10
Output
99

Less simple case Test
Input
3 6 10 20 44 30 12 37 10 45 44 55 14 34 10 20 44 29 12 34
Output
55

Validator 2 Validator
Input
4 7 10 20 44 30 12 37 22 10 66 44 -55 14 34 18 10 20 44 29 12 34 6 10 45 44 55 14 34 18
Output
66

No king Test
Input
6 5 2 3 4 5 6 2 3 4 5 6 2 3 4 5 6 2 3 4 5 6 2 3 4 5 6 2 3 4 5 6
Output
-666

Validator 3 Validator
Input
6 7 2 3 4 5 6 6 6 6 3 4 3 2 6 99 2 3 4 5 6 6 8 4 4 4 4 4 6 100 2 3 4 5 6 6 4 2 3 4 5 6 6 1
Output
-666

Not global maximum Test
Input
5 5 2 2 3 -1 -10 3 5 6 99 80 2 3 4 99 6 2 3 7 5 6 2 3 4 5 6
Output
7

Validator 4 Validator
Input
6 6 2 2 3 -1 -10 4 3 5 6 99 80 4 2 3 4 99 6 99 2 3 8 5 8 6 2 3 4 5 6 4 12 3 8 65 8 6
Output
8

Solution language

Solution

Stub generator input