Find Maximum Zeroes
Learn this problemProblem statement
In an Amazon analytics team, the Analysts collectively have a preference for the number zero and a disapproval towards negative numbers. Their objective is to determine the maximum number of zeroes achievable after performing a series of operations (possibly zero) on an array, all while avoiding negative values.
Formally, given an array arr of size n of positive integers, the Analysts can perform the following operation any number of times (possibly zero):
- Choose a prefix of size
s(1 ≤s≤n) that doesn't contain any zero (there is no indexisuch thatarr[i]= 0 and 1 ≤i≤s). - Decrease all values of this prefix by one, i.e., set
arr[i]=arr[i]- 1 for all 1 ≤i≤s.
Find the maximum number of zeroes that the array arr can contain after performing any (possibly zero) number of operations on the array.
Note that a prefix of size s in an array arr is the first s elements in this array, for example, the prefix of size 3 of array [3, 1, 5, 5, 2] is [3, 1, 5].
Function
findMaximumZeroes(arr: int[]) → int
Complete the function findMaximumZeroes in the editor.
findMaximumZeroes has the following parameters:
int arr[n]: the elements of the array.
Returns
int: the maximum number of zeroes that the array arr can contain after performing any (possibly zero) number of operations on the array.
𓍢ִ໋🌷͙֒ ᰔᩚ A massive thank you to chizzy_elect༊·° ♡
Examples
Example 1
arr = [4, 3, 5, 5, 3]return = 3
arr is 3, which is the maximum possible.Example 2
arr = [2, 5, 9, 3, 5]return = 1
arr is 1, which is the maximum possible.Constraints
n ≤ 2 * 105arr[i] ≤ 109More 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