FastPrepCourse Schedule
Problems/Course Schedule

Course Schedule

InMobi logoInMobi● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi new grad online assessment. Our version is about 99% the same as the reported InMobi online coding test prompt.

There are numCourses courses numbered from 1 through numCourses.

Each pair [course, prerequisite] in prerequisites means that prerequisite must be completed before course.

Return true if it is possible to complete every course. Return false if the prerequisite relationships contain a cycle.

Function

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

Examples

Example 1

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

Course 1 requires course 2, while course 2 requires course 1, so neither can be completed first.

Example 2

numCourses = 4prerequisites = []return = true

There are no prerequisites, so all four courses can be completed in any order.

Example 3

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

One valid order is 1, 2, 3, 4.

Constraints

  • 1 <= numCourses <= 5000
  • 0 <= prerequisites.length <= min(5000, numCourses * (numCourses - 1) / 2)
  • prerequisites[i].length == 2
  • 1 <= prerequisites[i][0], prerequisites[i][1] <= numCourses
  • prerequisites[i][0] != prerequisites[i][1]
  • No prerequisite pair appears more than once.

More InMobi Online Assessment questions

  • Validate a Bracket SequenceOA · Seen Oct 2026
  • Count Substrings Matching with One Adjacent SwapOA · Seen Oct 2026
  • Maximum Subarray with Start and End WindowsOA · Seen Oct 2026
  • Minimum Service Cold StartsOA · Seen Oct 2026
  • Range Maximum Subarray Sum QueriesOA · Seen Oct 2026
  • Connected Components with Divisor ThresholdOA · Seen Aug 2026
  • Maximize Impression ValueOA · Seen Aug 2026
  • Supply Path OptimizationOA · Seen Aug 2026
  • Delivery ServiceOA · Seen Jun 2026
  • Shared InterestOA · Seen Jun 2026

Similar questions at other companies

  • Distances to CyclesBelvedere Trading · OA
  • Course Schedule IIChainalysis · OAChainalysis interview questions
  • Can You Finish All Courses?Intuit · OAIntuit interview questions
  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
  • Course SchedulePlaud · ONSITE INTERVIEW
  • Find a Valid Course Completion OrderGoogle · ONSITE INTERVIEWGoogle interview questions
  • Course ScheduleByteDance · PHONE SCREENByteDance interview questions
  • Course ScheduleNykaa · PHONE SCREENNykaa interview questions
  • Course ScheduleKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public boolean canFinish(int numCourses, int[][] prerequisites) {
        // write your code here.
    }
}
Checking account…