Build Order for Simulink Model References With Cycle Report

Last updated: November 29, 2026

Quick Overview

Given a set of Simulink models and pairs (parent, child) meaning the parent model references the child, return a build order where every referenced model builds before its parents, breaking ties alphabetically, or report the models stuck in a reference cycle.

MathWorks
Coding & Algorithms
Software Engineer
MathWorks
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given a set of Simulink models and pairs (parent, child) meaning the parent model references the child, return a build order where every referenced model builds before its parents, breaking ties alphabetically, or report the models stuck in a reference cycle.

Simulink model referencing lets large teams split a controller into separately built models, and the build system must compile children before parents. MathWorks interviewers like this because it maps a real product problem to topological sorting and asks for a useful error, not just a boolean.

What the Interviewer Expects
  • Models the dependency direction correctly (child must come first)
  • Uses Kahn's algorithm and explains in-degree as 'unbuilt children remaining'
  • Uses a min-heap to make the order deterministic and alphabetical
  • Detects a cycle by counting emitted nodes and reports which models are involved
  • States O((V + E) log V) complexity
Key Topics to Cover
topological sort
Kahn's algorithm
cycle detection
priority queue
build systems
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you run independent builds in parallel on a pool of workers and estimate total build time?
  • How would you rebuild only what changed when one child model is edited?
  • How would you report the exact cycle path rather than every model blocked by it?
  • What changes if references can be conditional on a variant configuration?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: list of model names and list of (parent, child) edges. Output: a list containing every model once, with each child before all of its parents. Among models that are ready at the same time, pic...

High-Level Design

Treat each model's in-degree as the number of children it references that have not been built yet. Seed a min-heap with all models of in-degree 0 (leaf models). Pop the smallest, append it, and for ev...


Submit Your Answer
Markdown supported

Related Questions