Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Do BFS from the root. Let the root be at column 0. In the BFS, keep in the queue the node and its column.
When you traverse a node, store its value in the column index. For example, the root's value should be stored at index 0.
If the node has a left node, it column should be col - 1. Similarly, if the node has a right node, its column should be col + 1.
At the end, check the minimum and maximum col and output their values.