Data Structures & AlgorithmsHardProduct Company SDE · DAG DP
Problem: Which algorithm computes the longest path in a weighted directed acyclic graph in O(V + E)?
- A. Dynamic programming over a topological order
- B. Floyd-Warshall
- C. Kruskal's algorithm
- D. Dijkstra with a max-heap
Correct answer: A. Dynamic programming over a topological order
Processing vertices in topological order lets each DP value depend only on already-final predecessors.
More Coding Interview Problems questions
- Problem: What is the minimum number of colours that suffices for any planar graph?
- Problem: What is the time complexity of computing the KMP prefix function of a pattern of length m?
- Problem: Which structure supports push, pop and getting the minimum, all in O(1) amortised time?
- Problem: Which property makes counting sort stable and therefore usable inside radix sort?
- Problem: Which structure gives a queue with O(1) amortised enqueue, dequeue and minimum queries?
- Problem: The Chinese remainder theorem gives a unique solution modulo M for a system of congruences under which condition?