Data Structures & AlgorithmsHardCodeforces Div2 D · shortest paths

Problem: Which algorithm finds shortest paths in a grid where each cell weight is 0 or 1?

  1. A. 0-1 BFS with a deque
  2. B. Floyd-Warshall
  3. C. Prim's algorithm
  4. D. Topological sort

Correct answer: A. 0-1 BFS with a deque

A deque keeps distances sorted, pushing 0-weight moves to the front and 1-weight moves to the back.

More Coding Interview Problems questions

Exams that ask this topic