Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
Coding Round 2 Senior programming

LeetCode #207 - Course Schedule

You are given a number of courses you have to take, and can take course prerequisites as a directed graph. You need to determine if it's possible to finish all courses if prerequisites are given in pairs. This assesses your grasp on graph algorithms and cycle detection methods.
Function Signature: def can_finish(num_courses: int, prerequisites: List[List[int]]) -> bool:
Example 1:
  • Input: num_courses = 2, prerequisites = [[1,0]]

  • Output: True

  • Explanation: You can take course 0 first, then course 1.


Example 2:
  • Input: num_courses = 2, prerequisites = [[1,0],[0,1]]

  • Output: False

  • Explanation: There is a cycle in the prerequisites.


Constraints:
  • 1 <= num_courses <= 2000

  • 0 <= prerequisites.length <= 5000

  • prerequisites[i].length == 2.
Suggested Answer

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

Get Started Free

More Coding Round 2 Interview Prep

LeetCode #3 - Longest Substring Without Repeating Characters
Coding Round 1 · Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Link copied to clipboard