Reach the End in Time
Learn this problemProblem statement
A 2-D grid consisting of some blocked (represented as '#') and some unblocked
(represented as '.') cells is given. The starting position of a pointer is in the
top-left corner of the grid. It is guaranteed that the starting position is in an unblocked cell,
and it is also guaranteed that the bottom-right cell is unblocked. Each cell of the grid is
connected with its right, left, top, and bottom cells (if those cells exist). It takes 1 second
for a pointer to move from a cell to its adjacent cell. If the pointer can reach the bottom-right
corner of the grid within maxTime seconds, return the string 'Yes'.
Otherwise, return the string 'No'.
Function
reachTheEnd(grid: String[], maxTime: int) → String
Complete the function reachTheEnd in the editor.
reachTheEnd has the following parameter(s):
String[] grid: an array of strings representing the rows of the gridint maxTime: the maximum time to complete the journey
Examples
Example 1
grid = ["..##", "#.##", "#..."]maxTime = 5return = "Yes"Example 2
grid = ["..", ".."]maxTime = 3return = "Yes"Example 3
grid = [".#", "#."]maxTime = 2return = "No"Constraints
1 ≤ grid.length, grid[i].length ≤ 500- All rows have equal length and contain only
.and#. - The top-left and bottom-right cells are unblocked.
0 ≤ maxTime ≤ 10^5
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026