Algorithm · Google · Hard
You are given an m x n integer matrix grid. You may begin at any cell and walk to edge-adjacent cells (up, down, left, or right) to form a path. A path never visits the same cell twice. Look at any three consecutive cells on the path, denoted A -> B -> C, where A is the cell before B and C is the cell after B. The first step must satisfy value(B) <= value(A). Every later step must satisfy value(C) <= value(B) or value(C) <= value(A). That is, each new cell's value must be no…
Checking your access…