A beacon network is a binary tree. Beacons on the same tier share the same depth (the root is at depth 0). Report the largest number of beacons found on any single tier. Only actual beacons are counted; missing positions do not count.
Line 1: an integer k, the number of tokens on line 2.
Line 2: k space-separated tokens giving the tree in level order. The first token is the root; each subsequent token is an integer id or null for a missing child. Children of null nodes are omitted.
A single integer: the maximum number of beacons on any tier.
Example 1
Input
7 1 2 3 4 5 6 7
Expected
4
Explanation
Tier sizes are 1 (root), 2, and 4. The densest tier holds 4 beacons.
Example 2
Input
5 1 2 3 null 4
Expected
2
Explanation
Tier 0 has 1 beacon; tier 1 has 2 (nodes 2 and 3); tier 2 has just 1 (node 4, the right child of 2). The maximum is 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →