Course Schedule with Topological Sort
Last updated: June 17, 2026
Quick Overview
Given prerequisites for courses, determine if all courses can be finished and return a valid order. Tests topological sorting and cycle detection in directed graphs.
Google
Coding & Algorithms
Software Engineer
Software Engineer
Phone Screen
Coding & Algorithms
Medium
320
0
308 solved
Given prerequisites for courses, determine if all courses can be finished and return a valid order. Tests topological sorting and cycle detection in directed graphs.
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
This problem can be solved using topological sorting on a directed graph. The courses represent vertices and the prerequisites represent directed edges. The goal is to determine if there exists a ...
Approach
- Graph Representation: Use an adjacency list to represent the directed graph where each course has a list of its prerequisites.
- In-degree Tracking: Calculate the in-degree (number of prer...
Submit Your Answer
Markdown supported