← Questions

Shortest distance from all buildings

0
MetaWaymoGoogleCodingLast asked Nov 2026

A coding interview question asked in Google's first round (coding) and at Waymo and Meta, last asked Nov 2026. It tests bfs and grids.

You get an m x n grid where 0 is empty land, 1 is a building and 2 is an obstacle. You want to build a house on an empty cell so that the sum of its shortest walking distances to every building is as small as possible.

Sign in to unlock this question

The full prompt, the worked answer and your own canvas or code with the AI tutor. New accounts get 5 credits: each one unlocks a question for good.

Where it's asked

  • Google · First round: coding · Last asked Nov 202645 min · Coding in a Google Doc, no syntax highlighting or autocomplete · No AI
  • Waymo · Coding · Last asked Sep 202645 min · Usually two rounds; some give you the interviewer's buggy code to find and fix, some are read aloud with no skeleton
  • Meta · AI-enabled coding · Last asked Dec 202560 min · Several progressive tasks on a starter codebase in CoderPad with an AI assistant panel; usually two rounds · The first task usually without AI, later tasks with it

What it tests

bfs · grids

Your code and the AI tutor open when you unlock this question.