Problem · Array
Bitonic Partitioning
Learn this problemProblem statement
Partition arr into at least three non-empty contiguous segments. Represent each segment by its arithmetic mean.
A partition is valid when the sequence of means is strictly increasing up to one peak segment and then strictly decreasing. There must be at least one segment before and after the peak.
Return the exact number of valid partitions as a decimal string.
For [1, 3, 2, 1], the three valid partitions are:
[1] | [3, 2] | [1].[1] | [3] | [2, 1].[1] | [3] | [2] | [1].
Function
bitonicPartitioning(arr: int[]) → StringExamples
Example 1
arr = [1, 3, 2, 1]return = "3"The three valid partitions are listed in the statement.
Example 2
arr = [1, 2, 3, 4, 3, 2, 1]return = "49"Enumerating all cut positions and keeping only strictly increasing-then-decreasing mean sequences gives 49.
Constraints
1 <= arr.length <= 100.-10^9 <= arr[i] <= 10^9.