import
java.io.*;
class
GFG {
static
boolean
check(String s,
int
K,
int
limit)
{
int
[] count =
new
int
[
2
];
for
(
int
i =
0
; i < limit; i++) {
count[s.charAt(i) -
'0'
]++;
}
if
(K >= Math.min(count[
0
], count[
1
]))
return
true
;
for
(
int
i =
0
; i + limit < s.length(); i++) {
count[s.charAt(i) -
'0'
]--;
count[s.charAt(i + limit) -
'0'
]++;
if
(K >= Math.min(count[
0
], count[
1
]))
return
true
;
}
return
false
;
}
static
void
solve(String s,
int
n,
int
K)
{
int
Low =
1
, High = n;
int
ans =
0
;
while
(Low <= High) {
int
mid = Low + (High - Low) /
2
;
if
(check(s, K, mid)) {
ans = Math.max(ans, mid);
Low = mid +
1
;
}
else
{
High = mid -
1
;
}
}
System.out.print(
"Minimum length after deletion is: "
);
int
res = n - ans;
System.out.println(res);
}
public
static
void
main(String[] args)
{
String s =
"0110"
;
int
K =
2
;
int
n = s.length();
solve(s, n, K);
}
}