n × m grid of rooms. For each room you know opens[i][j], the moment (in seconds) from which you are allowed to **start moving into it** from a neighbouring room.
You stand in room (0, 0) at time t = 0 and move into rooms that share a wall with yours (up, down, left or right). You have twisted an ankle, so move durations alternate: the first move takes 1 second, the second takes 2, the third 1 again, the fourth 2, and so on. You may wait in place as long as you like; waiting does not reset the pattern.
Return the earliest moment you can be in room (n - 1, m - 1).opens=[[0, 3], [1, 9]] → 11
The first move, down to (1, 0), starts at 1 and lasts 1 second, so we arrive at 2. The door to (1, 1) opens at 9, and the second move lasts 2 seconds: we arrive at 11.
opens=[[0, 0, 0], [0, 0, 0], [0, 0, 0]] → 6
Four moves lasting 1, 2, 1 and 2 seconds: 6 seconds in total.
opens=[[0, 5, 0], [2, 7, 1]] → 9
opens=[[0, 3], [1, 9]]
11
Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.