AMAZON Coding Question – Solved

3 Live
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. Example: s = "000000" m = 3 Interval [3, 4] (1-based indexing) to get "001100", ensuring no segment of consecutive 0's has a length β‰₯ 3. Thus, the answer is 1. Constraints: - 1 ≀ n ≀ 2 * 10^5 - 1 ≀ m, k ≀ n - It is guaranteed that each character in s is '0' or '1'. FUNCTION s = "10101" m = 1 Input Format for Custom Testing Sample Case 0 Sample Input 0: STDIN 10101 1 1 Sample Output 0: 2 Explanation: - In one operation, we can flip only one bit.

Asked in: AMAZON

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |