FastPrepFastPrep
Problem Brief

Get Minimum Operations

FULLTIMEOA
See IBM online assessment and hiring insights

Implement a function that returns the minimum number of operations needed to ensure the string s (of length n) contains no segments of exactly m consecutive '0's.

In one operation, you can do the following:

  • Select a contiguous segment of length k and make every bit in this segment '1'.

The function getMinOperations will take three inputs:

  • string s: a string representing s.
  • int m: an integer representing m.
  • int k: an integer representing k.

The function should return an integer representing the minimum number of operations needed.

1Example 1

Input
s = "000000", m = 3, k = 2
Output
1
Explanation

We can perform an operation on the interval [3, 4] (1-based indexing) to get "001100", ensuring no segment of consecutive 0s has a length ≥ 3. Thus, the answer is 1.

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 2 * 10^5
  • 1 ≤ m, k ≤ n
public int getMinOperations(String s, int m, int k) {
  // write your code here
}
Input

s

"000000"

m

3

k

2

Output

1

Sign in to submit your solution.