Skip to content

Practice Populating Next Right Pointers in Each Node

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

Medium#116
LeetCode Problem

Populating Next Right Pointers in Each Node

Problem Statement

The input is a perfect binary tree: all leaves have the same depth, and every internal node has two children. Each Node stores val, left, right and next fields. Set next to the node immediately to its right on the same level, including across different parents; use null for the final node of each level. All next pointers start as null.

Source: Populating Next Right Pointers in Each Node on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
root = [1,2,3,4,5,6,7]
Output
[1,#,2,3,#,4,5,6,7,#]

# Example 2

Input
root = []
Output
[]

Constraints

The number of nodes in the tree is in the range [0, 2^12 - 1].
-1000 <= Node.val <= 1000

Related LeetCode Problems

Practice more problems similar to Populating Next Right Pointers in Each Node.

Review your practice with PhantomCodeAI

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