Minimum number of operations on a binary string such that it gives 10 ^ A as remainder when divided by 10 ^ B | Java implementation of the approach ; Function to return the minimum number of operations on a binary string such that it gives 10 ^ A as remainder when divided by 10 ^ B ; Initialize result ; Loop through last b digits ; Driver code
import java . util . * ; class GFG { static int findCount ( String s , int n , int a , int b ) { int res = 0 ; char [ ] s1 = s . toCharArray ( ) ; for ( int i = 0 ; i < b ; i ++ ) { if ( i == a ) { if ( s1 [ n - i - 1 ] != '1' ) res += 1 ; } else { if ( s1 [ n - i - 1 ] != '0' ) res += 1 ; } } return res ; } static public void main ( String [ ] args ) { String str = "1001011001" ; int N = str . length ( ) ; int A = 3 , B = 6 ; System . out . println ( findCount ( str , N , A , B ) ) ; } }