FastPrepFastPrep
Problem Brief

Max Subarray Filled With Zeros

OA
See Google online assessment and hiring insights

Given an array of integers, you can perform 2 operations on them.

Operation 1: You can make a[i] = a[i-1] - 1 (i >= 0 and i < size of array).

Operation 2: You can make a[i] = 0.

Input: Array A, int X, int Y.

Output: You have to print the max subarray filled with zeros that can be made by performing Operation 1 at the most X times and Operation 2 at the most Y times.

1Example 1

Input
A = [4, 3, 0, 1], X = 2, Y = 1
Output
3
Explanation

Step 1: [4, 0, 0, 1] X=2, Y=0

Step 2: [4, 0, 0, 0] X=1, Y=0

Therefore, the output is 3.

public int maxSubarrayFilledWithZeros(int[] A, int X, int Y) {
  // write your code here
}
Input

A

[4, 3, 0, 1]

X

2

Y

1

Output

3

Sign in to submit your solution.