← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Oracle SWE interview with a graph/scheduling problem that looked straightforward on the surface but had a few wrinkles worth knowing about going in.

Questions Asked (1)

Q1

Given n courses labeled 0 through n-1 and a list of prerequisite pairs, return any valid ordering in which all courses can be completed. Print the final order.

Algorithms & Data Structures
Author's notes

They threw in a simplifying constraint: each course has at most one direct prerequisite, so the graph is actually a forest rather than a general DAG.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the courses and prerequisites as a directed graph and use topological sorting to find a valid order. Apply Kahn's algorithm (BFS with in-degree tracking) or DFS with cycle detection, and clearly explain how you handle cycles by returning an empty order.

Pro tip: Mention that you would detect cycles and return an empty array if no valid order exists, and discuss the trade-offs between Kahn's algorithm and DFS-based topological sort in terms of readability and performance.

1. Clarify the problem and edge cases

Confirm that the input is a list of prerequisite pairs where [a, b] means b must be taken before a. Ask about possible cycles, duplicate edges, and whether all courses need to be included.

2. Choose the algorithm

Decide between Kahn's algorithm (BFS with in-degree) and DFS with cycle detection. Explain your choice based on simplicity and efficiency.

3. Build the graph and compute in-degrees

Create an adjacency list for the directed graph and an array to track in-degrees for each node.

4. Perform topological sort

Use a queue to process nodes with in-degree 0, appending them to the result and decrementing in-degrees of their neighbors. For DFS, use recursion with temporary and permanent marks to detect cycles.

5. Validate and return the result

Check if the result contains all n courses. If not, a cycle exists; return an empty array. Otherwise, return the order.

Key Points to Mention

  • Graph representation: adjacency list and in-degree array
  • Topological sorting using Kahn's algorithm (BFS) or DFS
  • Cycle detection: if the result size is less than n, a cycle exists
  • Time and space complexity: O(V + E) time, O(V + E) space
  • Handling edge cases: empty input, no prerequisites, multiple valid orders
  • Comparison of BFS vs DFS approaches and when to use each

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.