Given an array of positive integers arr, construct a binary tree satisfying the following conditions:
Each node has either
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:
arr.length
arr[i]
It is guaranteed that the answer fits into a
Given an array of positive integers arr, construct a binary tree satisfying the following conditions:
Each node has either
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:
arr.length
arr[i]
It is guaranteed that the answer fits into a