Earliest Time to Reach the Exit of a Timed Gate Grid

Last updated: November 29, 2026

Quick Overview

Each cell of a grid opens at a given time, and you may enter a cell only at or after its open time. Every second you must move to a neighboring cell; starting at the top-left at time 0, return the earliest time you can reach the bottom-right cell, or -1 if impossible.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Each cell of a grid opens at a given time, and you may enter a cell only at or after its open time. Every second you must move to a neighboring cell; starting at the top-left at time 0, return the earliest time you can reach the bottom-right cell, or -1 if impossible.

A harder Meta onsite grid question that blends Dijkstra with a parity argument. It could be framed as moving an avatar through a Horizon Worlds level whose doors unlock on a schedule. The interviewer looks for the insight that waiting is simulated by bouncing between two cells, which only ever adds an even number of seconds.

What the Interviewer Expects
  • Model arrival times with Dijkstra on the grid
  • Realize standing still is not allowed but bouncing back and forth simulates waiting
  • Derive the parity adjustment when arriving early
  • Detect the only impossible case: the first move is blocked
  • Explain why later arrivals at a cell are never useful
Key Topics to Cover
Dijkstra on grid
Parity reasoning
Time-dependent graphs
Matrix traversal
Greedy waiting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if standing still were allowed?
  • Prove that the first-move check is the only way to fail.
  • How does the answer change if some cells are permanently blocked walls?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Grid unlock of size R x C with unlock[0][0] == 0, sizes up to 1000 x 1000.
  • Each move takes exactly one second; staying put is not allowed.
  • Return the earliest arrival time at the bottom-ri...
High-Level Design

If you can make any first move, you can always kill time by stepping back and forth, which costs 2 seconds per round trip. So arriving at a neighbor at time t + 1 that is still locked until u mean...


Submit Your Answer
Markdown supported