Coding problem
The fewest steps across a warehouse floor
The task
A warehouse robot drives on a grid of floor cells: '.' is open floor and '#' is a shelf. Each move takes it one cell up, down, left or right, onto open floor.
Complete FewestSteps(string[] grid). Return the fewest moves from the top-left cell to the bottom-right cell, or -1 if the robot cannot get there, which includes the case where either of those cells is a shelf. The grid has at least one row and one column, and all rows have the same length.
Signature
public static int FewestSteps(string[] grid)
Examples
["...", "##.", "..."]→4. Right twice, then down twice.[".#", "#."]→-1. Shelves block both ways out of the start.
Limits: Up to 5,000 cells (for example 70 × 70). Grids are shown as rows of text.
The tests check: one cell, a shelf at the start or at the end, a long row, a winding corridor, floors where the first route found is not the shortest, and a 70 × 70 open floor in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// The fewest moves from the top-left to the bottom-right cell over '.' cells, or -1.
public static int FewestSteps(string[] grid)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.