Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Populating Next Right Pointers in Each Node

XPChallenge Points: 20
levelLevel: Medium

You are given a perfect binary tree (all leaves are at the same level and every parent has exactly two children).
Set each node’s next pointer to point to the node on its right in the same level.
If there is no node to the right, set next to NULL.

Example 1:

Input: root = [10,5,15,3,7,12,18]

Output: [10,#,5,15,#,3,7,12,18,#]

Explanation:

Each node’s next pointer connects to the node immediately on its right within the same level. # marks the end of a level.

Example 2:

Input: root = []

Output: []

Explanation:

The tree is empty, so there are no connections.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result