Loading...
Given an array of positive integers, find a contiguous subarray containing at least two numbers with the largest min + max.
min + max
Formally, given an array nums, find indices l and r (where r >= l + 1) that maximize min(nums[l..r]) + max(nums[l..r]). Return that maximum value.
nums
l
r
r >= l + 1
min(nums[l..r]) + max(nums[l..r])
Input: nums = [4, 9, 1, 1] Output: 13 Explanation: min + max of subarray [4, 9] = 4 + 9 = 13
Input: nums = [1, 2, 3, 1] Output: 5 Explanation: min + max of subarray [2, 3] = 2 + 3 = 5
nums.length
nums[i]
Click "Run" to test with sample cases or "Submit" to run all tests.