FastPrepNetwork Layer Execution Order
Problems/Network Layer Execution Order

Network Layer Execution Order

NVIDIA logoNVIDIA● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a phone screen for an NVIDIA software engineering internship. The interviewer gave a Network class that has one method to create a layer and another to record a data dependency between two layers. The candidate first reviewed the C++ code, then used the class to build a feed-forward block, and then wrote a valid order to run the layers, a topological sort.

The report shows no code, no input or output format and no rule for which valid order to return. We chose the input format (the layers in the order they were added, plus one [source, target] pair per dependency, where the target reads the source's output), the rule that runs the earliest-added ready layer first so there is exactly one answer, an empty list when the links form a cycle (including a layer linked to itself), that a repeated link counts as one dependency, that layers with no links still run, the limits, and all the examples; Example 1 is a small feed-forward block with a skip link, written for practice. The code review and the build step are not part of this problem.

Our version is about 60% the same as the reported question.

Given the layers of a network and the data links between them, return an order to run the layers in which every layer runs after all the layers it reads from, or an empty list if no such order exists.

The network is built with two calls. addLayer(name) adds a layer, and layers lists the layer names in the order they were added. addLayerOutput(source, target) sends the output of layer source to layer target. Each such call is one outputs[i] = [source, target], and it means source must run before target.

A layer is ready when every layer it reads from has already run. Whenever several layers are ready at the same time, run the one that was added first. This makes the answer unique.

A layer with no links still runs, and it takes its place by the same rule. The same link may be given more than once; it still means only that source runs before target. If the links form a cycle, including a layer linked to itself, no valid order exists: return an empty list.

Function

executionOrder(layers: List<String>, outputs: List<List<String>>) → List<String>

Examples

Example 1

layers = ["linear1","input","relu","linear2","add"]outputs = [["input","linear1"],["linear1","relu"],["relu","linear2"],["linear2","add"],["input","add"]]return = ["input","linear1","relu","linear2","add"]

input is the only layer that reads from no other layer, so it runs first. linear1 was added before input, but it reads input's output, so it has to wait. After input, only linear1 is ready (add still waits for linear2), so the chain linear1, relu, linear2 follows, and add runs last.

Example 2

layers = ["head_b","head_a","embed","merge","norm"]outputs = [["embed","head_a"],["embed","head_b"],["head_a","merge"],["head_b","merge"]]return = ["embed","head_b","head_a","merge","norm"]

At the start, embed and norm are both ready. embed was added earlier, so it runs first. Now head_b and head_a are ready too, and both were added before norm: head_b was added before head_a, so head_b runs, then head_a. Next merge is ready and was added before norm, so it runs, and norm, which has no links at all, runs last.

Example 3

layers = ["encoder","decoder","proj"]outputs = [["encoder","decoder"],["decoder","proj"],["proj","decoder"]]return = []

decoder reads from proj, and proj reads from decoder, so neither can run before the other. No valid order exists, so the answer is an empty list, even though encoder on its own could run.

Constraints

  • 1 <= layers.length <= 1000
  • Each layer name has 1 to 20 characters, each a lowercase letter, a digit or _, and no name appears twice in layers.
  • 0 <= outputs.length <= 4000
  • outputs[i].length == 2
  • outputs[i][0] and outputs[i][1] are both in layers. They may be the same layer.

More NVIDIA Phone Screen questions

  • Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
  • Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
  • Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
  • Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
  • Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
  • Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
  • Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
  • Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
  • Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
  • Merge Multiple Sorted StreamsPHONE SCREEN · Seen Aug 2026

Similar questions at other companies

  • Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
  • Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
  • Dependency-Aware Task SchedulerRippling · PHONE SCREENRippling interview questions
  • Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Merge Subsequences Into a Consistent Total OrderGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Lexicographic Dependency OrderIllumio · PHONE SCREENIllumio interview questions
  • Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Order Sources by Their DependenciesRetool · PHONE SCREENRetool interview questions
  • Dependency-Aware Agent Task SchedulerOpenAI · PHONE SCREENOpenAI interview questions

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public List<String> executionOrder(List<String> layers, List<List<String>> outputs) {
        // Write your code here.
    }
}
Checking account…