Example 1
- Input
- matrix = [[9,9,4],[6,6,8],[2,1,1]]
- Output
- 4
Coordinates (2,1) → (2,0) → (1,0) → (0,0) give values 1 → 2 → 6 → 9, so four cells form a legal path. Equal adjacent 9s and 1s cannot extend it. Every starting cell has length at most 4, as the dry runs show.