FastPrepCourse Schedule Cycle Detection
Problems/Course Schedule Cycle Detection

Course Schedule Cycle Detection

Google logoGoogle● MediumINTERNNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Google SWE intern report posted in February 2026 says the interview asked for directed-cycle detection to decide whether a valid course schedule exists. We rebuilt the usual course labels, the direction of the prerequisite pairs, the input limits, the function signature, and the return type. Our version is about 93% the same as the reported question.

There are numCourses courses labeled from 0 to numCourses - 1. You are given a list prerequisites, where prerequisites[i] = [course, prerequisite] means that prerequisite must be completed before course.

Return true if it is possible to finish every course. Otherwise, return false.

Function

canFinish(numCourses: int, prerequisites: int[][]) → boolean

Examples

Example 1

numCourses = 2prerequisites = [[1,0]]return = true

Take course 0 before course 1.

Example 2

numCourses = 2prerequisites = [[1,0],[0,1]]return = false

Each course depends on the other, so the dependency graph contains a directed cycle.

Example 3

numCourses = 4prerequisites = [[1,0],[2,1],[3,2]]return = true

The courses can be completed in the order 0, 1, 2, 3.

Constraints

  • 1 <= numCourses <= 2000.
  • 0 <= prerequisites.length <= 5000.
  • prerequisites[i].length = 2.
  • 0 <= course, prerequisite < numCourses.
  • Every prerequisite pair is unique.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
  • Package Install OrderVerily · ONSITE INTERVIEW
  • Task Build Order and File-Change RerunsVanta · PHONE SCREEN
  • Course SchedulePlaud · ONSITE INTERVIEW
  • All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Audit Discounted Category AncestorsFaire · ONSITE INTERVIEW
  • Course ScheduleNykaa · PHONE SCREENNykaa interview questions
  • Detect a Cycle in a Directed GraphMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
  • Effective Role PrivilegesSnowflake · PHONE SCREENSnowflake interview questions

Interview reports that mention this question

  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google New Grad Onsite, Reverse Coin Change: 1 Experience
  • Google SWE and PhD Intern Coding: 14 Experiences (Part 3 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google OA: What It Tests (2026)
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public boolean canFinish(int numCourses, int[][] prerequisites) {
        // Write your code here.
    }
}
Checking account…