Passing Balls: Medium Version

The binary tree above has a height of 2 and has 4 leaves. You are going to pass down a ball from the root (the topmost node). Every node other than the leaves has a switch. If a node is switched off, the ball will pass to its left child; if a node is switched on, the ball will pass to its right child. After passing the ball, the switch will toggle (if it's on it becomes off and vice versa). Initially, every node is switched off.

Chris built a similar tree of height \(8\) with the same indexing. Which leaf will contain the \(36^\text{th}\) ball?

Note: the indexes of the leaves should be in the range \([256,512)\).

You are advised to solve the Easy version of this problem first.
Find this too simple? Try the Hard version of this problem.

Problem Loading...

Note Loading...

Set Loading...