FastPrepFewest Terms to Finish All Courses
Problems/Fewest Terms to Finish All Courses

Fewest Terms to Finish All Courses

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You find the fewest terms needed to take every course. Some courses must come before others, and any number of courses can be taken in one term. An Adobe SDE-2 report (January 2024, about three and a half years of experience, result still pending) says its first round had two DSA questions. One was built on a sliding window. The other it calls similar to a course-scheduling problem, and it gives a link. It gives nothing beyond that link. It names no changes from the linked task, and gives no limits or examples.

The rules are those of the linked task, since the report does not say what was different. That includes returning -1 when a cycle makes it impossible. We chose these limits: up to 1000 courses and 2000 rules. We wrote new examples.

Our version is about 75% the same as the reported question.

There are n courses, numbered from 1 to n. Each entry [before, after] of relations means course before must be finished in an earlier term than course after.

In one term you may take any number of courses, as long as every rule that ends at a course you take has its before course finished in an earlier term.

Return the fewest terms needed to take all n courses, or -1 if it cannot be done.

Function

minimumTerms(n: int, relations: int[][]) → int

Examples

Example 1

n = 4relations = [[1,2],[1,3],[3,4]]return = 3

Term 1: course 1. Term 2: courses 2 and 3 (both need only course 1). Term 3: course 4 (needs course 3). So 3 terms.

Example 2

n = 5relations = []return = 1

No course needs another, so all five can be taken in the first term.

Example 3

n = 4relations = [[1,2],[2,3],[3,2],[1,4]]return = -1

Course 2 needs course 3 and course 3 needs course 2, so neither can ever be taken: the answer is -1.

Constraints

  • 1 <= n <= 1000
  • 0 <= relations.length <= 2000
  • relations[i].length == 2, 1 <= relations[i][0], relations[i][1] <= n and relations[i][0] != relations[i][1]
  • No pair appears twice in relations.

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Course ScheduleByteDance · PHONE SCREENByteDance interview questions
  • Course ScheduleNykaa · PHONE SCREENNykaa interview questions
  • Topological Sort for Ads TasksNetflix · PHONE SCREENNetflix interview questions
  • Course ScheduleBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Task Order With PrerequisitesDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Course Schedule FeasibilityTesla · PHONE SCREENTesla interview questions
  • Job Schedule with One Initial Ready JobDatadog · PHONE SCREENDatadog interview questions
  • Course SchedulePlaud · ONSITE INTERVIEW
  • Find a Valid Course Completion OrderGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Adobe SDE and Senior SWE Interviews: 9 Experiences (Part 3 of 6)
  • Adobe Experienced Hire Interviews: 55 Experiences (Part 1 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int minimumTerms(int n, int[][] relations) {
        // Write your code here.
    }
}
Checking account…