Answer: VMware OA Question 2024 July | Graphs | on-campus
Answer · Posted Jun 2026
Solution: Course Schedule — Topological Sort (Kahn's BFS) Approach This problem reduces to cycle detection in a directed graph. If a cycle exists, not all courses can be completed. We use Kahn's Algorithm (BFS Topological Sort): Build an adjacency list and compute the in-degree (number of prerequisites) for each course. Enqueue all courses with in-degree 0 (no prerequisites). Process nodes from the queue: for each processed course, reduce the in-degree of its neighbors. If a neighbor's in-degree drops to 0, ...
The full answer & interview discussion are available to premium members.
Log in Create a free account