Problem · Array
Maximize Sum of Array
Learn this problemProblem statement
You are given an array of integers. Your task is to maximize the sum by performing the following operations repeatedly until the array is empty:
- Choose any element from the current array that hasn't been removed before.
- Add this element to your total sum.
- Remove the first and last elements of the array.
Return the maximum sum you can achieve following these steps.
Function
maximizeSum(arr: int[]) → intExamples
Example 1
arr = [4, 4, 8, 5, 3, 2]return = 17Steps:
- Choose 5 from [4, 4, 8, 5, 3, 2]
- Remove 4 and 2
- Total sum = 5
- Choose 4 from [4, 8, 5, 3]
- Remove 4 and 3
- Total sum = 5 + 4 = 9
- Choose 8 from [8, 5]
- Remove 8 and 5
- Total sum = 9 + 8 = 17
Constraints
🐳More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026