Learn
Exam

Delta Search in a Two-Dimensional Array 2

Difficulty
BEGINNER

Problem

In a given two-dimensional array, a cell is considered a local maximum if its value is greater than or equal to all adjacent cells in the up, down, left, and right directions.

Given a n x m two-dimensional array numbers, write a function solution that returns the count of local maximum cells in numbers.


Constraints

  • The dimensions of numbers (n and m) are between 2 and 20 inclusive. n and m can be different.
  • Each element numbers[i][j] is a natural number between 1 and 1,000 inclusive.

Test Case

Test Case Number numbers return
1 [[5,7,14],[3,3,11],[14,10,9],[6,15,7],[15,14,11]] 4
2 [[9,12],[1,6],[9,3],[15,14]] 2
3 [[1,1,1],[1,1,1],[1,1,1]] 9

Explanation for Test Case 1

  • The situation given in the problem is illustrated as follows, where marked cells are local maximums:

Explanation for Test Case 2

  • The situation given in the problem is illustrated as follows, where marked cells are local maximums:

Explanation for Test Case 3

  • The situation given in the problem is illustrated as follows, where marked cells are local maximums: