As reported: Goldman Sachs Analyst Superday DSA round (2025): print the diagonal traversal of a binary tree — for the tree with root 1, children 2 and 3, and grandchildren 4, 5 (under 2) and 7, 6 (under 3), the diagonals are
1 2 4,3 5 7and6.
Diagonals run down and to the left: the root is on diagonal 0; a left child is on the same diagonal as its parent; a right child is on the next diagonal (d + 1). Return the diagonals in order 0, 1, 2, …; within a diagonal list the nodes from top to bottom, and left to right on the same level (level order).
Example 1
root = [1,2,3,4,5,7,6]
-> [[1,2,4],[3,5,7],[6]]
1
/ \
2 3
/ \ / \
4 5 7 6
Example 2
root = [8,3,10,1,6,null,14,null,null,4,7,13]
-> [[8,3,1],[10,6,4],[14,7,13]]
Constraints: 0 ≤ nodes ≤ 10^4; node values are integers.
Code runner format: one JSON value per line: root as a LeetCode level-order array (null for missing children). Implement diagonals(root); the harness prints the list of diagonals.