O(1) space , simple bfs java solution and without recursion
Intution: Treating level of tree is as linked list.\n1. From parent level connect children level node as linked list and parent level is already connected so we
Intution: Treating level of tree is as linked list.\n1. From parent level connect children level node as linked list and parent level is already connected so we can move to next node of parent to connect other children node.\n```\nclass Solution {\n    public Node connect(Node root) {\n        Node head = root;\n         for(head = root; head != null;){\n             \n             if(head.left == null){                  // if left is null then it means no children nodes to connect now\n                 return root;\n             }\n             Node prev = null;\n             Node curr = head;                      //curr always pointing starting node of every level in starting\n             \n             while(curr != null){\n                 \n                if(prev != null)                             //  for first node of every level, prev pointing to null\n                prev.right.next = curr.left;          //connect prev node right to curr left node\n                curr.left.next = curr.right;          // connect same children nodes of parent \n                 \n                 prev = curr;                              // move prev and curr node to next node\n                 curr = curr.next;\n             }\n             head = head.left;                        // move head to next level\n         }\n        return root;\n    }\n}\n```
['Breadth-First Search', 'Java']