Return a valid course completion order

Quick Overview

This question evaluates understanding of graph algorithms and dependency resolution, specifically skills in cycle detection and producing valid orderings of tasks.

Return a valid course completion order

Company: Oracle

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an integer `n` representing `n` courses labeled `0..n-1` and a list of prerequisite pairs `prerequisites`, where each pair `[a, b]` means you must complete course `b` before course `a`. Return any valid ordering of courses you can take to finish all courses. If it is impossible due to cyclic prerequisites, return an empty list. Requirements: - The solution should run efficiently for large `n` and prerequisite lists.

Quick Answer: This question evaluates understanding of graph algorithms and dependency resolution, specifically skills in cycle detection and producing valid orderings of tasks.

|Home/Coding & Algorithms/Oracle
Oracle logo
Oracle
Jan 26, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
11
0

You are given an integer n representing n courses labeled 0..n-1 and a list of prerequisite pairs prerequisites, where each pair [a, b] means you must complete course b before course a.

Return any valid ordering of courses you can take to finish all courses. If it is impossible due to cyclic prerequisites, return an empty list.

Requirements:

  • The solution should run efficiently for large n and prerequisite lists.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...