Skip to content

Practice All Possible Full Binary Trees

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#894
LeetCode Problem

All Possible Full Binary Trees

Problem Statement

Given an integer n, return a list of all possible full binary trees with n nodes. Each node of each tree in the answer must have Node.val == 0. Each element of the answer is the root node of one possible tree. You may return the final list of trees in any order. A full binary tree is a binary tree where each node has exactly 0 or 2 children.

Source: All Possible Full Binary Trees on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 7
Output
[[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]

# Example 2

Input
n = 3
Output
[[0,0,0]]

Constraints

1 <= n <= 20

Related LeetCode Problems

Practice more problems similar to All Possible Full Binary Trees.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.