Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Search on Grids and Graphs
00:00
5 left

Search on Grids and Graphs

MediumPython

Problem

A BrainOS robot represents a mapped floor area as a rectangular grid. Free cells are marked 0, and blocked cells such as walls or unavailable areas are marked 1. Given a start cell and a goal cell, return the shortest route the robot can follow using four-directional movement.

If multiple shortest routes exist, explore neighbors in this order: up, right, down, left. Return the first route produced by that ordering. If the goal cannot be reached, return an empty list.

Formal Specification

Implement navigate_grid(grid, start, goal).

  • grid is a non-empty rectangular list of lists containing integers 0 or 1.
  • start and goal are two-element lists [row, column] identifying free cells.
  • The robot may move to an adjacent cell vertically or horizontally, but not diagonally or through blocked cells.
  • Return a list of coordinate lists beginning with start and ending with goal, or [] when no route exists.

Constraints

  • 1 <= rows, columns <= 200
  • grid is rectangular and contains only 0 and 1
  • start and goal are coordinates of free cells
  • Movement is limited to four cardinal directions
  • The returned route must include both endpoints when one exists

Function Signature

def navigate_grid(grid, start, goal):
Interviewer

Your question is Search on Grids and Graphs. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.