All problems
0113EasyTreeDepth-First SearchBreadth-First SearchBinary Tree

Chime Hangs True

Tracked in this browser only
Write code

Trains the technique from

LeetCode 101Symmetric Tree

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A workshop assembles wind chimes. Everything hangs from one top hook, and each hook or arm may carry up to two arms below it, one on its left side and one on its right side. Every arm has a weight stamped on it.

Because the harness passes plain JSON, the chime arrives as the array joints, listed row by row from the top hook downwards. The first entry is the top hook's weight. After that, entries come in pairs: the next two entries give the left-side arm and the right-side arm of the next piece in that same row order. A side with nothing hanging on it is written null, and a null contributes no pair of its own.

A chime is called true when it is its own reflection: swap left for right everywhere below the top hook and you get the identical assembly, with matching weights and matching empty sides.

Return true if the chime is true, and false if it is not.

Examples

Example 1

Input
joints = [4, 7, 7, 2, 9, 9, 2]
Output
true

The two arms under the hook both weigh 7, and their pairs 2 then 9 on one side face 9 then 2 on the other, so every piece meets its reflection.

Example 2

Input
joints = [8, 3, 3, 7]
Output
false

The left arm carries a 7 on its own left side while the right arm carries nothing at all, so the reflection breaks one row below the hook.

Example 3

Input
joints = [6, 2, 2, 5, null, null, 5]
Output
true

The 5 hangs on the outer side of each 2, which is exactly where a reflection puts it.

Constraints

  • The number of arms in the chime is in the range [1, 1000].
  • -100 <= joints[i] <= 100
  • Entries that are not `null` are integers; `null` marks an empty side.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def chime_hangs_true(joints: list) -> bool:
Java
public boolean chimeHangsTrue(Integer[] joints)
September 7
Apply