Problem · Array
Max Subarray Filled With Zeros
Learn this problemProblem statement
Given an array of non-negative integers, you can perform two operations.
Operation 1: Choose an index i with A[i] > 0 and set A[i] = A[i] - 1.
Operation 2: Choose an index i and set A[i] = 0.
Return the maximum length of a contiguous subarray that can be filled with zeros by performing Operation 1 at most X times and Operation 2 at most Y times.
Function
maxSubarrayFilledWithZeros(A: int[], X: int, Y: int) → intExamples
Example 1
A = [4, 3, 0, 1]X = 2Y = 1return = 3Step 1: [4, 0, 0, 1] X=2, Y=0
Step 2: [4, 0, 0, 0] X=1, Y=0
Therefore, the output is 3.
Constraints
1 <= A.length <= 2 * 10^50 <= A[i], X <= 10^90 <= Y <= A.length
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026