Find Contiguous Subarray with Largest Min Plus Max π -- Not OA but an INTERVIEW Question! π· :)
Given an array of n positive integers, find a contiguous subarray
(containing more than one number) with the largest min + max.
Complete the function findContiguousSubarrayWithLargestMinPlusMax in the editor.
findContiguousSubarrayWithLargestMinPlusMax has the following parameter:
int nums[n]: an array of integers
Returns
int: the largest sum of min and max of a contiguous subarray
Note
Solve better than O(n^3)
π‘ π«§A HUGE THANK YOU TO THE INCREDIBLE RACHEL!π π§‘
1Example 1
The contiguous subarray with the largest min + max is [8, 10], where the min is 8 and the max is 10. Therefore, the answer is 10 + 8 = 18.
2Example 2
The contiguous subarray with the largest min + max is [2, 9], where the min is 2 and the max is 9. Therefore, the answer is 2 + 9 = 11.
Constraints
Limits and guarantees your solution can rely on.
π