Forward interview question

LC-like 2D array traversal/manipulation question