Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional
Problem: Courses 0–5 have prerequisites: 1 needs 0, 2 needs 1, 3 needs 2, 4 needs 5, 5 needs 4. A course can be taken only after all its prerequisites are finished. How many courses can never be completed?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Kahn's topological sort removes courses whose prerequisites are done; the leftovers are stuck in or behind a cycle. Counting courses with prerequisites instead answers a different question.
More Coding Interview Problems questions
- Problem: Buses run fixed routes; from a stop, the number of distinct routes is what matters. Given the four routes [1,2,7], [3,6,7]…
- Problem: In the array [3, 1, 4, 1, 5, 9, 2, 6] an element is visible from the left if it is strictly greater than every element before it…
- Problem: Find the area of the largest rectangle in a histogram with bar heights [2, 1, 5, 6, 2, 3] (each bar has width 1).
- Problem: Remove exactly 3 digits from the number "1432219" to make the smallest possible number (leading zeros are not allowed in the…
- Problem: How many trailing zeros does 1000! have in base 10?
- Problem: The string "BANANA" has how many distinct arrangements of its letters (letters are identical when they match)?