Data Structures & AlgorithmsVery hardICPC regional · Codeforces Div2 D

Problem: A 4×4 grid has obstacles at (1,1), (1,2), (2,1) (row, column, 0-indexed). Movement is up, down, left or right. How many distinct shortest paths exist from (0,0) to (3,3)?

  1. A. 3
  2. B. 1
  3. C. 2
  4. D. 4

Correct answer: C. 2

BFS that accumulates path counts only along edges into the next layer counts shortest paths exactly. Counting all paths, including longer detours, is a different (and much larger) quantity.

More Coding Interview Problems questions

Exams that ask this topic