Code RoomMonorepo tree height
EasyPrep Room Coding #4744

Monorepo tree height

CodingAlgorithms & data structuresEntry–Mid~16 min

A monorepo build tool describes a release as a list of edges. Every entry of edges is one string written parent>child, meaning the module named before the marker pulls in the module named after it directly. The edges arrive in whatever order the scanner emitted them, so the root is not always mentioned first. The structure is a tree: exactly one module is never listed as a child, and every other module is listed as a child exactly once. Module names are non empty and never contain the marker character. Compilation walks down from the root, so the team wants the module that sits furthest from it. Return the name of the module at the greatest distance from the root, counting the root itself as distance 0. If several modules tie at that greatest distance, return whichever of them sorts first alphabetically. Return an empty string when edges is empty.

Implement
deepest_build_target(edges: list[str]) → str
Examples
in[["app>core","app>ui","core>utils"]]out"utils"
in[["r>a","r>b"]]out"a"
in[["y>x","z>y"]]out"x"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 16 min
InputExpectedGot
[["app>core","app>ui","core>utils"]]"utils"not run yetsample
[["r>a","r>b"]]"a"not run yetsample
[["y>x","z>y"]]"x"not run yetsample