As part of your Day 1 orientation at Amazon, your new team is hosting a programming challenge. You've been asked to participate in completing the following task. Given an array of integers, perform certain operations in order to satisfy some constraints.
The constraints are as follows:
- The first array element must be
1. - For all other elements, the difference between adjacent integers must not be greater than
1. In other words, for1 <= i < n,arr[i] - arr[i - 1] <= 1.
To accomplish this, the following operations are available:
- Rearrange the elements in any way.
- Reduce any element to any number that is at least
1.
What is the maximum value that can be achieved for the final element of the array by following these operations and constraints?
Complete the function maximumFinal in the editor below.
maximumFinal has the following parameter:
int arr[n]: an array of integers
Returns:
int: the maximum value that can be achieved for the final element of the array given the conditions above
Duplicate note (July 2, 2026) 𐔌՞ ܸ.ˬ.ܸ՞𐦯 : This problem and Maximize Final Element are the same question. I merged the sighting dates from both pages into this version.
Examples
01 · Example 1
arr = [3, 1, 3, 4] return = 4
- Subtract
1from the first element, making the array[2, 1, 3, 4]. - Rearrange the array into
[1, 2, 3, 4]. - The final element's value is
4, the maximum value that can be achieved. Therefore, the answer is4.
Constraints
1 <= n <= 10^51 <= arr[i] <= 10^9
More Amazon problems
- Closest Version DateONSITE INTERVIEW · Seen Jul 2026
- Maximum Concurrent Processes (Bar Raiser Round)ONSITE INTERVIEW · Seen Jul 2026
- Maximum Product New RatingOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Get Distinct Pairs (Also apply to AS intern)Seen Jul 2026
- Minimum Delivery Center InconvenienceOA · Seen Jun 2026
- Unfulfilled Customers by Inventory PriorityOA · Seen Jun 2026
- Minimum Operations to Make the Integer ZeroSeen Jun 2026
public int maximumFinal(int[] arr) {
// write your code here
}arr[3, 1, 3, 4]
expected4
checking account