BackmediumRecursion Oracle Uber

Galaxy Height Mapper Solution

Problem Statement

Given a galaxy with planetary systems of varying heights, calculate the maximum height of the galaxy using recursion.

Example 1
Input
{'A': {'B': 2, 'C': 1}, 'B': {'D': 0}, 'C': {}}
Output
3

Explanation: Step-by-step: for galaxy {'A': {'B': 2, 'C': 1}, 'B': {'D': 0}, 'C': {}}, we calculate the maximum height of 'A' as 1 + max(height of 'B', height of 'C') = 1 + max(2, 1) = 3.

Example 2
Input
{'Y': {'Z': 0}}
Output
1

Explanation: Step-by-step: for galaxy {'Y': {'Z': 0}}, we calculate the maximum height of 'Y' as 1 + 0 = 1.

Constraints

  • Each system has a unique identifier.
  • The input graph is a tree (no cycles).
  • The maximum number of systems is 100.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free