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
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. We can swap first two characters, S becomes 0101. and the value of S will be 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 S: Represents the given string. •K: Represents the integer. Input format Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
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 D 00111001 0 Sample output
4 5 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #include<bits/stdc++.h> using namespace std; int solve (string S, long long K) { // write your code here } int main() { } ios::sync_with_stdio(0); cin.tie(0); string S; cin>>S; long long K; cin >> K; int out_; out_ = solve(S, K); cout << out_;