← Oracle Interview Insights

Oracle·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Oracle SWE interview with a graph/topological sort problem. Pretty standard algorithmic round but the cycle detection piece is where things get interesting.

Questions Asked (1)

Q1

Given n courses labeled 0 to n-1 and a list of prerequisite pairs, return a valid order to complete all courses. If a cycle exists in the prerequisites, return an empty list.

Algorithms & Data Structures
Author's notes

Classic topological sort but I kept second-guessing whether to go BFS (Kahn's) or DFS with coloring.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the prerequisites as a directed graph and use topological sorting to find a valid course order. If the topological sort does not include all courses, a cycle exists, so return an empty list.

Pro tip: Mention both Kahn's algorithm (BFS) and DFS-based topological sort, and discuss their trade-offs. Also, clarify edge cases like disconnected graphs and self-loops.

1. Understand the problem

Restate the problem: given n courses and prerequisite pairs, find an order to take all courses, or return empty if impossible. Clarify that each pair [a, b] means b must be taken before a.

2. Model as a graph

Represent courses as nodes and prerequisites as directed edges. Choose adjacency list representation for efficiency.

3. Choose a topological sort algorithm

Select either Kahn's algorithm (BFS with in-degree) or DFS with cycle detection. Explain the steps of the chosen algorithm.

4. Detect cycles

If using Kahn's, check if the result contains all n courses; if not, a cycle exists. If using DFS, track visited and recursion stack to detect back edges.

5. Return the result

If no cycle, return the topological order; otherwise, return an empty list. Discuss time and space complexity.

Key Points to Mention

  • Graph representation: adjacency list for O(V+E) space.
  • Topological sorting algorithms: Kahn's (BFS) and DFS-based.
  • Cycle detection: in-degree count or recursion stack.
  • Time complexity: O(V+E) for both algorithms.
  • Edge cases: disconnected graph, self-loop, multiple valid orders.
  • Handling large inputs: iterative vs recursive DFS to avoid stack overflow.

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