FastPrepCourse Schedule
Problems/Course Schedule

Course Schedule

Kotak Mahindra Bank logoKotak Mahindra Bank● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Course Schedule without restating its full contract. This practice version uses the conventional task, examples, constraints, and runnable interface.

There are numCourses courses labeled from 0 through numCourses - 1. Each pair [course, prerequisite] means that prerequisite must be completed before course.

Return true if it is possible to complete every course. Return false when the prerequisite graph contains a directed cycle.

Function

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

Examples

Example 1

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

Course 0 can be completed before course 1.

Example 2

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

Each course requires the other first, so the graph contains a cycle.

Example 3

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

One valid completion order is 0, 1, 2, 3.

Constraints

  • 1 <= numCourses <= 2000
  • 0 <= prerequisites.length <= 5000
  • Every prerequisite pair contains two distinct valid course labels.
  • No prerequisite pair appears more than once.

More Kotak Mahindra Bank problems

  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Nov 2026
  • Maximum Non-Adjacent Coins in Two RowsONSITE INTERVIEW · Seen Oct 2026
All Kotak Mahindra Bank interview questionsSee Kotak Mahindra Bank hiring insights
Saved
class Solution {
    public boolean canFinish(int numCourses, int[][] prerequisites) {
        // Write your solution here
    }
}
Checking account…