Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost Tree From Leaf Values

Try to solve the Minimum Cost Tree From Leaf Values problem.

Statement

Given an array of positive integers arr, construct a binary tree satisfying the following conditions:
Each node has either 00 or 22 children.
The values of arr correspond to the leaf values obtained in an inorder traversal of the tree.
The value of each non leaf node equals the product of the largest leaf value in its left subtree and the largest leaf value in its right subtree.

Return the minimum possible sum of all non leaf node values among all such valid binary trees.

Constraints:

  • 2≤2 \le arr.length ≤40\le 40

  • 1≤1 \le arr[i] ≤15\le 15

  • It is guaranteed that the answer fits into a 3232 bit signed integer, which is less than 2312^{31}.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Cost Tree From Leaf Values

Try to solve the Minimum Cost Tree From Leaf Values problem.

Statement

Given an array of positive integers arr, construct a binary tree satisfying the following conditions:
Each node has either 00 or 22 children.
The values of arr correspond to the leaf values obtained in an inorder traversal of the tree.
The value of each non leaf node equals the product of the largest leaf value in its left subtree and the largest leaf value in its right subtree.

Return the minimum possible sum of all non leaf node values among all such valid binary trees.

Constraints:

  • 2≤2 \le arr.length ≤40\le 40

  • 1≤1 \le arr[i] ≤15\le 15

  • It is guaranteed that the answer fits into a 3232 bit signed integer, which is less than 2312^{31}.