import java.util.*;

public class Solution {

```
public static int minimumNet(int n, int k, boolean[] fish){
// Write your code here.
int ans = Integer.MAX_VALUE;
boolean catchingPossible = checkPossibleOrNot(fish, k);
if (!catchingPossible) {
return -1;
}
ans = getMinimumLength(fish, k, ans);
return ans;
}
private static int getMinimumLength(boolean[] fish, int k, int ans) {
int count = 0, len = 0;
Queue<Integer> q = new LinkedList<>();
for (int i = 0; i < fish.length; i++) {
if (fish[i]) {
count++;
q.add(i - 1);
}
if (count == k) {
len = i - q.poll();
if (len < ans) {
ans = len;
}
count--;
}
}
return ans;
}
private static boolean checkPossibleOrNot(boolean[] fish, int k) {
int count = 0;
for (int i = 0; i < fish.length; i++) {
if (fish[i]) {
count++;
}
}
return count >= k;
}
```

}