Back to problems

Populating Next Right Pointers in Each Node

Algorithm · LinkedIn · Medium

Given a perfect binary tree, assign every next pointer to the node immediately to its right on the same level. A node with no neighbor to its right must have its next pointer set to NULL. Input Format: You receive the root of a perfect binary tree Node; its height h is within [1, 12]. Output Format: Update the original tree directly; no return value is required. Constraints: Only constant additional space may be used. Space consumed by recursive calls is permitted. Example:…

Checking your access…