Short Problem Definition:
You are given a square map of size n×n. Each cell of the map has a value denoting its depth. We will call a cell of the map a cavity if and only if this cell is not on the border of the map and each cell adjacent to it has strictly smaller depth. Two cells are adjacent if they have a common side.
time complexity is O(N^2)
space complexity is O(1)
*pun* You only get your cavities checked on an airport */pun*
I check all 4 surrounding elements if they are strictly smaller. If so, I mark the position with an ‘X’. Better runtime than n^2 is not possible as every element has to be visited!