mediumRecursionPattern: Mixed

Max Height Calculation Solution

Problem Statement

Given a tree structure represented as a dictionary where each key is a node identifier and its corresponding value is a list of its child nodes, calculate the maximum height of the tree using recursion.

Constraints

  • Each system has a unique identifier.
  • The input graph is a tree (no cycles).
  • The maximum number of systems is 100.
Time: O(n) Space: O(h)
The optimal approach utilizes recursion to calculate the maximum height of the galaxy, where each system's height is determined by the maximum height of its orbiting systems plus one, leading to a time complexity of O(n).

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.