← DiffPush

Introduction to Trees

Baseline Binary Trees · Traversals O(1) · O(1)

The Knockout Bracket Blueprint

A tournament organizer is drafting a single-elimination bracket on a whiteboard. The first round is a single title-holder at the top, and every subsequent round can field at most twice as many contenders as the round before it, because each slot in a round spawns at most two slots in the next. The organizer wants a one-line formula so the venue can be sized for any round number without redrawing the whole board.

Input: A single integer n — the 1-indexed level of the binary tree.

Output: Return one integer: the maximum number of nodes that can exist on level n.

Constraints

Examples

Example 1

Input: {"n":1}
Output: 1
Level 1 holds only the root, so the cap is 1.

Example 2

Input: {"n":3}
Output: 4
Doubling each round: level 2 holds 2, level 3 holds 2^(3-1) = 4.

Solve this in your browser →

Also on LeetCode ↗