BudiBadu Logo
00:00

Chronicle Walkway Binding

Recursion Hard 0 views

The Chronicle Walkway in the city of Merislav is an enchanted promenade lined with glyph tiles. Each tile glows when paired tiles at mirrored positions emit simultaneously. Given a set of synchronized notes that describe which tiles glow together, sages want to compute the farthest distance between simultaneously glowing tiles so that visitors know how wide the reflections reach.

Each entry in notes is either:

  • a plain integer index (meaning a single tile), or
  • a pair [left, right] where left and right are themselves notes describing groups that glow at the same time.

When a plain integer appears, its glowing range is just that index. When a pair appears, its range stretches from the smallest index covered by its left part to the largest index covered by its right part. The distance contributed by a pair is therefore max_right(left) - min_left(left), max_right(right) - min_left(right), and the distance between the furthest tile on the left subtree and the furthest tile on the right subtree. The maximum distance in the entire structure is the answer.

Formally, define:

  • If node is an integer k, then min(node) = max(node) = k and diameter(node) = 0.
  • If node is [left, right], then recursively compute min, max, and diameter for left and right. Then
    min(node) = min(min(left), min(right))
    max(node) = max(max(left), max(right))
    diameter(node) = max(diameter(left), diameter(right), max(right) - min(left)).

Return diameter(notes) as an integer. The input structure may be deeply nested. Your solution must operate recursively, propagating the necessary bounds and diameter upward.

Example 1:

Input: notes = 5
Output: 0

Example 2:

Input: notes = [1, 4]
Output: 3

Example 3:

Input: notes = [[1, 3], [6, [7, 10]]]
Output: 9

Explanation: The left structure spans tiles 1..3, the right spans 6..10 (because of the nested pair). The farthest simultaneous tiles are 1 and 10 (distance 9).

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.

BudiBadu Logo

Chronicle Walkway Binding

Recursion Hard 0 views

The Chronicle Walkway in the city of Merislav is an enchanted promenade lined with glyph tiles. Each tile glows when paired tiles at mirrored positions emit simultaneously. Given a set of synchronized notes that describe which tiles glow together, sages want to compute the farthest distance between simultaneously glowing tiles so that visitors know how wide the reflections reach.

Each entry in notes is either:

  • a plain integer index (meaning a single tile), or
  • a pair [left, right] where left and right are themselves notes describing groups that glow at the same time.

When a plain integer appears, its glowing range is just that index. When a pair appears, its range stretches from the smallest index covered by its left part to the largest index covered by its right part. The distance contributed by a pair is therefore max_right(left) - min_left(left), max_right(right) - min_left(right), and the distance between the furthest tile on the left subtree and the furthest tile on the right subtree. The maximum distance in the entire structure is the answer.

Formally, define:

  • If node is an integer k, then min(node) = max(node) = k and diameter(node) = 0.
  • If node is [left, right], then recursively compute min, max, and diameter for left and right. Then
    min(node) = min(min(left), min(right))
    max(node) = max(max(left), max(right))
    diameter(node) = max(diameter(left), diameter(right), max(right) - min(left)).

Return diameter(notes) as an integer. The input structure may be deeply nested. Your solution must operate recursively, propagating the necessary bounds and diameter upward.

Example 1:

Input: notes = 5
Output: 0

Example 2:

Input: notes = [1, 4]
Output: 3

Example 3:

Input: notes = [[1, 3], [6, [7, 10]]]
Output: 9

Explanation: The left structure spans tiles 1..3, the right spans 6..10 (because of the nested pair). The farthest simultaneous tiles are 1 and 10 (distance 9).

00:00
Loading editor...
Test Results

Run your code to see test results

Click the Submit button to execute your solution

Related Problems

No related problems found

Comments (0)

Join the Discussion

Share your thoughts, ask questions, or help others with this problem.