Gilt Groupe

1 DSA problems asked in Gilt Groupe coding interviews

0 Easy
1 Medium
0 Hard
​

1 problem

Trees
1
Add One Row to Tree
Medium

Given the `root` of a binary tree and two integers `val` and `depth`, add a row of nodes with value `val` at the given `depth`. The root is at depth `1`. - For every non-null node `cur` at depth `depth - 1`, create two new nodes with value `val`: one becomes `cur`'s new left child and one becomes `cur`'s new right child. - `cur`'s original left subtree becomes the left subtree of the new left node, and `cur`'s original right subtree becomes the right subtree of the new right node. - If `depth == 1`, there is no depth `0`, so create a new root with value `val` whose left subtree is the whole original tree. Return the root of the modified tree.