Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Maximum Binary Tree (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given an integer array nums with no duplicates, construct a maximum binary tree from a given array by following these rules:

  • The root of the tree is the highest value in the nums.
  • The left subtree is recursively built from the elements to the left of the highest value in subarray prefix.
  • The right subtree is recursively built from the elements to the right of the highest value in subarray suffix.

Return the resulting maximum binary tree.

Examples

Example 1:

  • Input: nums = [4, 3, 1, 7, 0, 5]
  • Expected Output:

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible