give binary treestruct Node int val Node leave Node right Node nextPopulate pointer point right node if right node pointer set nullinitially pointer set NULL Example 1input root 12345null7output 123457explanation give binary tree Figure a function populate pointer point right node like Figure B the serialized output level order connect pointer signify end levelexample 2input root Output ConstraintsThe number nod tree range 0 6000100 Nodeval 100 FollowupYou use constant extra spacethe recursive approach fine you assume implicit stack space count extra space problem