Given a binary string str of length N and two integers A and B such that 0 ≤ A < B < n. The task is to count the minimum number of operations on the string such that it gives 10A as remainder when divided by 10B. An operation means changing 1 to 0 or 0 to 1.
Input: str = “1001011001”, A = 3, B = 6
The string after 2 operations is 1001001000.
1001001000 % 106 = 103
Input: str = “11010100101”, A = 1, B = 5
Approach: In order for the number to give 10A as remainder when divided by 10B, the last B digits of the string has to be 0 except the digit at (A + 1)th position from the last which should be 1. Therefore, check the last B digits of the string for the above condition and increase the count by 1 for each mismatch of digit.
Below is the implementation of the above approach:
- Minimum number of operations required to sum to binary string S
- Count of integers obtained by replacing ? in the given string that give remainder 5 when divided by 13
- Largest number less than or equal to Z that leaves a remainder X when divided by Y
- Program to find remainder when large number is divided by 11
- Largest number by which given 3 numbers should be divided such that they leaves same remainder
- Program to find remainder when large number is divided by r
- Minimum given operations required to convert a given binary string to all 1's
- Minimum operations required to convert a binary string to all 0s or all 1s
- Minimum number of given operations required to convert a string to another string
- Find the remainder when First digit of a number is divided by its Last digit
- Find the remainder when N is divided by 4 using Bitwise AND operator
- Find minimum number to be divided to make a number a perfect square
- Minimum number of swaps to make two binary string equal
- Minimum number of replacements to make the binary string alternating | Set 2
- Minimum number of characters to be removed to make a binary string alternate
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.