Find Contiguous Subarray with Largest Min Plus Max π -- Not OA but an INTERVIEW Question! π· :)
Updated
Problem statement
Given an array of n positive integers, find a contiguous subarray
(containing more than one number) with the largest min + max.
Function
findContiguousSubarrayWithLargestMinPlusMax(nums: int[]) β int
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)
Examples
Example 1
nums = [4, 6, 2, 8, 10]return = 18The 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.
Example 2
nums = [6, 2, 9, 1, 7]return = 11The 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
2 <= nums.length <= 10^51 <= nums[i] <= 10^9
More Google interview questions
- Evaluate a Nested Math ExpressionPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW Β· Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW Β· Seen Nov 2026
- Route Pattern MatcherPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN Β· Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN Β· Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW Β· Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW Β· Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN Β· ONSITE INTERVIEW Β· Seen Nov 2026
Similar questions at other companies
- Minimum Cost to Merge Values into OnePayPal Β· OAPayPal interview questions
- Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon Β· OA
- Minimum Cost of Left and Right PropagationAmazon Β· OA
- Minimum Rounds to Complete All TasksInfosys Β· OAInfosys interview questions
- Reschedule Meetings for Maximum Free TimeFivetran Β· OAFivetran interview questions
- Maximum Easy Tasks After RearrangingIBM Β· OAIBM interview questions
- Minimum Cost K-Capable ModelsMicrosoft Β· OAMicrosoft interview questions
- Maximum ScoreNVIDIA Β· OANVIDIA interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot Β· OA
- Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company Β· OAMcKinsey & Company interview questions