AMAZON Coding Question – Solved

6 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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |