Trionic Array II
You are given an integer array nums of length n.
A trionic subarray is a contiguous subarray nums[l...r] with 0 <= l < r < n for which there exist indices l < p < q < r such that:
nums[l...p]is strictly increasing.nums[p...q]is strictly decreasing.nums[q...r]is strictly increasing.
Return the maximum sum of any trionic subarray in nums.
Example 1
Input
nums = [0,-2,-1,-3,0,2,-1]Output
-4Choosing
l = 1, p = 2, q = 3, and r = 5 gives the trionic subarray [-2, -1, -3, 0, 2] with sum -4.Example 2
Input
nums = [1,4,2,7]Output
14Choosing
l = 0, p = 1, q = 2, and r = 3 gives the trionic subarray [1, 4, 2, 7] with sum 14.Constraints
- 4 <= n = nums.length <= 10^5
- -10^9 <= nums[i] <= 10^9
- It is guaranteed that at least one trionic subarray exists.