Practice Maximum Binary Tree II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A maximum binary tree is built from an array of distinct values by choosing its maximum as root, recursively building the left subtree from the values before that maximum and the right subtree from the values after it; an empty subarray gives null. You receive this tree's root, not its original array. Append val to the end of that hidden array and return the maximum tree for the extended array. All values, including val, are distinct.
Source: Maximum Binary Tree II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
root = [4,1,3,null,null,2], val = 5
[5,4,null,1,3,null,null,2]
# Example 2
root = [5,2,4,null,1], val = 3
[5,2,4,null,1,null,3]
# Example 3
root = [5,2,3,null,1], val = 4
[5,2,4,null,1,3]
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Binary Tree II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.