Back to problems

Contiguous Subarray with Largest Min + Max

Algorithm · ByteDance · Easy

Requirements You are given an array of n positive integers. Choose a contiguous subarray with at least two elements so that its minimum + maximum is as large as possible, and return that value. Example: Notes The key observation is that every subarray with length at least 2 can be viewed through pairs of positions (i, j) where i < j, using min(nums[i..j]) + max(nums[i..j]). The best possible result comes from neighboring elements: evaluate max(nums[i] + nums[i+1]) across…

Checking your access…