As reported: Amazon SDE-1 university-hire interview (India, January 2025), round 1 — Connect Nodes at Same Level, but with a
nextLeftpointer instead ofnextRight. Selection sort and the merge step of merge sort followed, with Leadership Principle questions about learning new technologies.
Each node of a binary tree (not necessarily complete) has an extra pointer nextLeft, initially null. Set every node's nextLeft to the node immediately to its left on the same level; the leftmost node of each level keeps nextLeft = null. Return the root.
This mirrors LeetCode 117 — Populating Next Right Pointers in Each Node II, which links to the right.
Example 1
1
/ \
2 3
/ \ \
4 5 7
root = [1,2,3,4,5,null,7]
Output: [1,#,3,2,#,7,5,4,#]
The output lists each level by starting at its rightmost node and following nextLeft, with # after each level.
Example 2
root = []
Output: []
Constraints: 0 ≤ number of nodes ≤ 6000; −100 ≤ Node.val ≤ 100.
Code runner format: one line: the tree as a level-order JSON array with null. Implement connect(root) on nodes with fields val, left, right, nextLeft; the harness prints the levels through nextLeft as shown above.