Reported September 2026
Applied Intuitiongraph

Compilation Order with Topological Sort

Reported by candidates from Applied Intuition's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Applied Intuition OA. Under 2s to a working solution.
Founder's read

The edge case that kills a naive solution on this Applied Intuition OA, reported in September 2026, is the tie-break. Plain topological sort gives you a valid order, but the problem wants the lexicographically smallest one every time multiple modules are ready. It's a dependency graph with up to 2 * 10^5 modules and edges, so the approach has to be near linear. Miss the ordering rule and you fail hidden tests while the examples pass. If you blank on the heap, StealthCoder is the invisible safety net running during the live assessment.

The problem

You are given a list of module names and a list of dependency pairs. Each dependency [a, b] means module a depends on module b, so b must be compiled before a.
Return one valid compilation order that includes every module exactly once. If multiple modules are currently available to compile, choose the lexicographically smallest available module first so the result is deterministic.
If the dependency graph contains a cycle, return a single-element array ["IMPOSSIBLE"].

Function
compilationOrder(modules: String[], dependencies: String[][]) → String[]
Complete the function compilationOrder in the editor below.
compilationOrder has the following parameters:
String[] modules: all module names
String[][] dependencies: dependency pairs [module, prerequisite]
Returns String[]: a valid compilation order, or ["IMPOSSIBLE"] if the dependencies contain a cycle.

Examples
Example 1
modules = ["A", "B", "C", "D"]
dependencies = [["A", "B"], ["A", "C"], ["D", "A"]]
return = ["B", "C", "A", "D"]
Both B and C are initially available, so lexicographical order chooses B before C.
Example 2
modules = ["A", "B"]
dependencies = [["A", "B"], ["B", "A"]]
return = ["IMPOSSIBLE"]
The two modules depend on each other, so no valid compilation order exists.

Constraints
1 <= modules.length <= 2 * 10^5
0 <= dependencies.length <= 2 * 10^5
All module names are distinct.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The pattern is Kahn's algorithm with a min-heap instead of a plain queue. Build the graph so prerequisite b points to dependent a. Count in-degrees for every module, including ones with no edges. Push all zero in-degree modules into a min-heap of strings. Pop the smallest, append it to the result, then decrement each neighbor's in-degree and push any that hit zero. If the result length is less than the module count, a cycle exists, so return ["IMPOSSIBLE"]. Pitfalls: flipping the edge direction, forgetting isolated modules, and using a FIFO queue, which breaks the lexicographic rule. Complexity is O((V+E) log V). Use a hash map for in-degrees and adjacency lists. If the heap logic slips under pressure, StealthCoder can surface the working solution during the live OA.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Compilation Order with Topological Sort cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Applied Intuition's OA.

Applied Intuition reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Compilation Order with Topological Sort FAQ

What's the trick in this compilation order problem?+

Run Kahn's topological sort but swap the queue for a min-heap. That makes every choice among available modules the lexicographically smallest. Detect cycles by checking whether the output has fewer modules than the input. That's the whole problem.

How do I detect the IMPOSSIBLE case?+

After the heap empties, compare the result length to the number of modules. If it's smaller, some modules never reached in-degree zero, which means a cycle. Return ["IMPOSSIBLE"] in that case. Don't try to detect cycles separately with DFS.

Which direction should the edges go?+

A pair [a, b] means a depends on b, so b compiles first. Add an edge from b to a and increment a's in-degree. Flipping this gives you the reverse order, and Example 1 will catch it immediately if you trace it by hand.

Will this pass the 2 * 10^5 constraints?+

Yes. Kahn's with a heap runs in O((V+E) log V), which is fine at 2 * 10^5 nodes and edges. Avoid re-sorting a list each step, since that turns it quadratic and times out on large inputs.

How do I prepare for this in 48 hours?+

Write Kahn's algorithm from scratch twice, once with a queue and once with a heap. Then test a cycle, an isolated module, and a tie between two ready modules. Those three cases cover nearly every failure on this problem type.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Applied Intuition.

OA at Applied Intuition?
Invisible during screen share
Get it