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
Shortest Path in 3D Grid
00:00
5 left

Shortest Path in 3D Grid

HardPython

Problem

A robot operating in a GM Factory ZERO workcell must move through a 3D grid containing traversable cells and blocked cells. Implement shortest_path_3d to return the least-cost path between two coordinates.

Formal Specification

The grid is represented as grid[z][y][x]. Each cell contains -1 for an obstacle or a nonnegative traversal cost for a free cell. Moving to an adjacent free cell costs the value of the destination cell. The starting cell's cost is not included. The robot may move in six directions: positive or negative x, y, or z.

Return the path as a list of coordinates in [z, y, x] format, including both start and end. Return [] if the destination is unreachable. The start and end coordinates are guaranteed to be in bounds and free.

Constraints

  • 1 <= depth, height, width <= 100
  • The grid is rectangular and contains at most 10^6 cells
  • Each free-cell cost is an integer from 0 through 9
  • Blocked cells are represented by -1
  • Movement is limited to six axis-aligned directions
  • The start and end cells are in bounds and free

Function Signature

def shortest_path_3d(grid, start, end):
Interviewer

Your question is Shortest Path in 3D Grid. 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.