Add One Row To Tree

easy
1. Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. 
 2. The root node is at depth 1.
 3. The adding rule is: given a positive integer depth d, for each NOT null tree nodes N in depth d-1, create two tree nodes with value v as N's left subtree root and right subtree root. And N's original left subtree should be the left subtree of the new left subtree root, its original right subtree should be the right subtree of the new right subtree root. If depth d is 1 that means there is no depth d-1 at all, then create a tree node with value v as the new root of the whole original tree, and the original tree is the new root's left subtree.

Input Format

First line contains two integers v and d. Second line contains a string representing the values of nodes or may contain null(representing the absence of a node) in level-order.

Output Format

return the root of the modified tree.

Constraints

The given d is in range [1, maximum depth of the given tree + 1].
 The given binary tree has at least one tree node.

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
1 3
4 2 null 3 1
Output
2 <= 4 => .
1 <= 2 => 1
3 <= 1 => .
. <= 3 => .
. <= 1 => 1
. <= 1 => .
Next
Cameras In Binary Tree

Related Questions