Good string? Given a binary string (consisting of O's and 1's only) and an integer K. We have to make the value of the s
Posted: Tue Jul 12, 2022 8:05 am
do so. If it is impossible to do so, print -1. Example Consider S=1001, K = 0. Currently, the value of S is 1 2 1 that is 2. S We can swap first two characters, S becomes 0101. and the value of S will b 0. So, the answer will be 1. Function description Complete the solve function provided in the editor. This function takes the following 2 parameters and returns the minimum number of operations to make the value of the string equal to K. S. Represents the given string. K: Represents the Integer. Input format Note: This is the input format that you must use to provide curto shown
Input format Note: This is the input format that you must use to provide custom input (available above the Compile and Test button). • There are two lines in the input, the first line has the string S. • The second line has an integer K Output format • Print the minimum number of operations to make the value of string equal to K, or -1 if it's impossible. Constraints 1< Number of zeroes in string 45 1< Number of ones in the string 45 1≤K<1012 Code snippets (also called starter code/boilerplate code) This question has code snippets for C, CPP, Java, and Python. Sample input 00111001 0 Sample output
1 #include<bits/sed++.h> using namespace std; 7 9 10 11 2 3 4 5 6 7 18 19 28 21 12 13 14 15 16 17 20 int solve (string S, long long K) { } int main() { } ios::sync_with_stdio(0); cin.tie(0); string S; cin>>S; long long K; cin >> K; int out; = solve(S, K); out cout << out_;