Find Contiguous Subarray with Largest Min Plus Max π -- Not OA but an INTERVIEW Question! π· :)
See Google hiring insights
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!π π§‘
nums = [4, 6, 2, 8, 10] return = 18
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.
nums = [6, 2, 9, 1, 7] return = 11
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.
π- Periodic Table Word FormationsPHONE SCREEN Β· Seen Jun 2026
- Split and Sort ArraySeen Jun 2026
- Fountain SafetyONSITE INTERVIEW Β· Seen Jun 2026
- Consolidate On-Call RotationsOA Β· Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW Β· Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW Β· Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN Β· Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN Β· Seen May 2026
public int findContiguousSubarrayWithLargestMinPlusMax(int[] nums) {
// write your code here
}