Tap here to switch tabs
Problem
Submissions

Problem: Maximum Binary Tree

Maximum Binary Tree builds a binary tree from an array of unique values: the largest value becomes the root, with each side formed recursively from the subarray on that side.

Statement

You are given an integer array nums containing unique values.

A maximum binary tree is constructed recursively using the following rules:

  • Create a root node whose value is the maximum element in nums.

  • Recursively construct the left subtree using the subarray of elements located to the left of the maximum element.

  • Recursively construct the right subtree using the subarray of elements located to the right of the maximum element.

Return the root node of the maximum binary tree.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 0≤0 \leq nums[i] ≤1000\leq 1000

  • All integers in nums are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Binary Tree

Maximum Binary Tree builds a binary tree from an array of unique values: the largest value becomes the root, with each side formed recursively from the subarray on that side.

Statement

You are given an integer array nums containing unique values.

A maximum binary tree is constructed recursively using the following rules:

  • Create a root node whose value is the maximum element in nums.

  • Recursively construct the left subtree using the subarray of elements located to the left of the maximum element.

  • Recursively construct the right subtree using the subarray of elements located to the right of the maximum element.

Return the root node of the maximum binary tree.

Constraints:

  • 1≤1 \leq nums.length ≤1000\leq 1000

  • 0≤0 \leq nums[i] ≤1000\leq 1000

  • All integers in nums are unique.