-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathZero_Count.cpp
More file actions
67 lines (57 loc) · 1.48 KB
/
Zero_Count.cpp
File metadata and controls
67 lines (57 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
You are given a binary string B of length L which contains K ones and remaining zeros. You are required to place the K ones in the binary string in such a way that the longest consecutive zeros have the least length possible. Once such a binary string is constructed, you are required to print the length of the contiguous block of zeros, which has the largest length.
Input Format
Single line consisting of two space separated integers denoting
L
L and
K
K.
Output Format
Print a single integer denoting the length of the longest consecutive zeros as per the problem.
Constraints
0
≤
K
≤
L
0≤K≤L
1
≤
L
≤
1
0
6
1≤L≤10
6
Sample 1:
Input
Output
3 1
1
Explanation:
B is of length 3 and it has 1 one’s.
So the possible strings as per the problem are 010, 001, 100.
In the first case, the maximum length of consecutive zeros is 1 whereas in the other two cases it is 2. Hence the constructed binary string is 010 and the output is 1.
Sample 2:
Input
Output
3 3
0
Explanation:
B is of length 3 and it has all three one’s. There is no block of zeros, hence the output is 0.
// -------------------------------------------------------- SOLUTION ---------------------------------------------------------------------- //
#include <bits/stdc++.h>
using namespace std;
int longest(int l,int k){
if(k == 0) return k;
else if(k == l) return 0;
else{
int min = (l-k)/(k+1);
return min;
}
}
int main() {
int L,K;
cin >> L >> K;
cout << longest(L,K) << endl;
}