Course Schedule Mock Interview

  1. ✓Problem→
  2. 2Clarifying Questions→
  3. 3Constraints→
  4. 4Brute Force→
  5. 5Complexity Analysis→
  6. 6Pattern Recognition→
  7. 7Optimized Solution→
  8. 8Implementation→
  9. 9Testing→
  10. 10Follow-Up→
  11. 11Evaluation
Problem

There are numCourses courses labelled 0 … numCourses - 1. You are given a list prerequisites where [a, b] means you must take course b before course a. Return true if it is possible to finish all courses, and false otherwise.

Constraints
  • 1 ≤ numCourses ≤ 10^5
  • 0 ≤ prerequisites.length ≤ 5·10^3
  • all pairs [a, b] are distinct
Example
in: numCourses = 2, prerequisites = [[1,0]]
out: true

Clarify

Before choosing anything: what would you ask the interviewer? What assumptions are you making? (Duplicates? Empty input? Value ranges? What to return when there is no answer?)