Data Structures & AlgorithmsHardCodeforces Div2 D · shortest paths
Problem: Which algorithm finds shortest paths in a grid where each cell weight is 0 or 1?
- A. 0-1 BFS with a deque
- B. Floyd-Warshall
- C. Prim's algorithm
- 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
- Problem: Which technique counts subarrays with sum at most K in a non-negative array in O(n)?
- Problem: What is the time complexity of subset-sum over n items with a bitset of width W (up to 10^5)?
- Problem: What is the purpose of the low-link value in Tarjan's strongly connected components algorithm?
- Problem: What is the worst-case complexity of the SPFA (queue-based Bellman-Ford) shortest path algorithm?
- Problem: Which property must hold for Huffman coding to produce an optimal prefix code?
- Problem: What is the complexity of Kruskal's algorithm when edges are already sorted and union-find uses path compression and union by rank?