Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Solution: Problem Challenge 1: Connect All Level Order Siblings

Problem Statement

Given a binary tree, connect each node with its level order successor. The last node of each level should point to the first node of the next level.


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


This problem follows the Binary Tree Level Order Traversal pattern. We can follow the same BFS approach. The only difference will be that while traversing we will remember (irrespective of the level) the previous node to connect it with the current node.




Like the course? Get enrolled and start learning!