A code editor stores its window layout as a binary tree. Each node is a pane, and splitting a pane gives it up to two child panes, left and right.
Write maxNesting(root) that returns how many panes are on the longest path from the root pane down to a pane with no children. An empty layout (root is null) returns 0.
The examples show the tree in level order, with null for a missing child.
Input: root = [1,2,3,4,5] Output: 3
The path 1 → 2 → 4 has three panes.
Input: root = [1,null,2,null,3] Output: 3
Each pane has only a right child, so all three are on one path.
0 <= number of panes <= 10000Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #316 Deepest Split Pane. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.