Sharing my Java O(1) extra space code
public void connect(TreeLinkNode root) {\n        TreeLinkNode cur;\n        TreeLinkNode nextLevel = root;\n        while (nextLevel != null) {\n            cu
    public void connect(TreeLinkNode root) {\n        TreeLinkNode cur;\n        TreeLinkNode nextLevel = root;\n        while (nextLevel != null) {\n            cur = nextLevel;\n            // at each level, connects the children nodes\n            while (cur != null && \n                    cur.left != null // checking for leaf nodes\n                    ) \n            {\n                cur.left.next = cur.right;\n                if (cur.next != null) {\n                    cur.right.next = cur.next.left;\n                }\n                cur = cur.next; \n            }\n            \n            nextLevel = nextLevel.left;\n            \n        }\n    }
['Java']