Browse Curriculum
FAANGPrep Sprint
Medium

Course Schedule

Determine if it is possible to finish all courses given prerequisites.

Problem Understanding

There are numCourses courses labeled 0 to numCourses - 1. You are given prerequisites array where [a, b] means taking course b is mandatory before a.

Return true if you can finish all courses, false otherwise (i.e., if there is a cycle).

Strategy (Kahn's Algorithm)

This is a Cycle Detection problem in a Directed Graph.

  • Build Adjacency List and In-Degree array.

  • Push all nodes with in-degree == 0 to Queue.

  • Process Queue, decrementing neighbor in-degrees.

  • Count how many nodes we processed.

  • If processed_count == numCourses, return true.

Interactive Visualization

Step 1 / 1

Visualization coming soon...

Initializing...

1x

Watch how Kahn's Algorithm processes nodes with 0 in-degree. Nodes turn green when processed.

Stop Guessing, Start Mastering.

Build the FAANG intuition. Master this pattern with optimized implementations, visual dry runs, and our curated collection of high-yield problems.