As reported: Okta Staff Software Engineer, Bangalore (2026), round 1 tech screen (a pass/fail gate) with a senior engineer, on CodeSignal's shared editor: a graph / topological-sort problem framed as real-world dependency resolution. Design the classes first, walk through examples, then code a full working solution with edge cases.
You have numCourses items labelled 0 … numCourses − 1 (packages, build targets, services) and a list of dependencies [a, b], meaning b must come before a. Return any order of all items that satisfies every dependency, or an empty list if no such order exists. This is LeetCode 210 — Course Schedule II.
Example 1
numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]] -> [0,1,2,3] (or [0,2,1,3])
Example 2
numCourses = 2, prerequisites = [[1,0],[0,1]] -> [] (0 and 1 depend on each other)
Clarifications
- Any valid order is accepted.
- Items with no dependencies may appear anywhere that respects the rest.
Constraints: 1 ≤ numCourses ≤ 2000; 0 ≤ prerequisites.length ≤ numCourses · (numCourses − 1); all pairs are distinct.
Code runner format: one JSON value per line: numCourses, then prerequisites (LeetCode's format). Implement findOrder(numCourses, prerequisites); the harness checks your order and prints "ok", or [] when you report that no order exists.