Graphs interview questions

Grids and networks as graphs: BFS and DFS, multi-source BFS, topological order, union-find, Dijkstra and minimum spanning trees, with the costs you need to state.

5 quick facts

– interview-ready · 22 questions in this topic

– of 22 tried

Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.

Questions

  1. Count the separate patches of land on a mapPredict
  2. Can every task finish, given its prerequisites?Pick the fix
  3. Minutes until every item on a shelf spoilsFill the blank
  4. How many separate groups does a network have?Predict
  5. Fewest hops between two stationsPick the fix
  6. Fastest delivery time to every depotPredict
  7. The earliest valid task orderPredict
  8. Seat guests at two tables with no feud at eitherPick the fix
  1. Which cable closes a loop?Predict
  2. Area of the biggest patch of landPredict
  3. Repaint the connected region of a picturePick the fix
  4. Fewest one-letter changes between two code wordsPredict
  5. Does a dependency graph contain a loop?Pick the fix
  6. Cheapest way to cable every office togetherOrder the steps
  7. Cells whose rain reaches both coastsPick the fix
  8. Fill in the water that does not touch the edgePredict
  9. Adjacency list, adjacency matrix or edge list?Predict
  10. BFS or DFS: which one to usePick the fix
  11. Mark visited when you push or when you pop?Predict
  12. Why Dijkstra fails with negative weightsPick the fix
  13. Union-find: how it works and when to reach for itPredict
  14. Grids are graphs: neighbours, bounds and costsPredict

Practise this topic

Flashcards · 33

Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.

Quick quiz · 22 questions

One exercise per question, checked as you go. Needs JavaScript.

Mock interview · 4 sets

Timed, out loud, then tick what you covered. Needs JavaScript.

Quick facts

Recall the answer first, then tap Show to check.

Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license