O45

Course Schedule (Cycle Detection)

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: BOOLEAN

Problem Statement & Objective

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. Return True if you can finish all courses.

Function Signature (Python)

course_schedule_cycle_detection(num_courses: int, prerequisites: list[list[int]]) -> bool

Input & Output Contract

Output Rule:True veya False.

System Constraints

1 <= ders_sayisi <= 2000
0 <= on_kosullar.length <= 5000
0 <= a, b < ders_sayisi, a != b

Example Execution Walkthrough

ders_sayisi = 2, on_kosullar = [[1, 0]] -> önce 0 sonra 1 alınır -> True
ders_sayisi = 2, on_kosullar = [[1, 0], [0, 1]] -> döngü var -> False

Example Test Scenarios (3)

Example 1: Valid
Input:[2,[[1,0]]]
Expected Output:true
Example 2: 2'li Döngü
Input:[2,[[1,0],[0,1]]]
Expected Output:false
Example 3: Doğrusal
Input:[3,[[0,1],[1,2]]]
Expected Output:true
Loading Python Editor...
Input Parameters
[
  2,
  [
    [
      1,
      0
    ]
  ]
]
Expected Output
true