There are nunique virus variants in an infinite 2D grid. You are given a 2D array points, where points[i] = [xi, yi] represents a virus originating at (xi, yi) on day 0. Note that it is possible for
multiple virus variants to originate at the same point.
Every day, each cell infected with a virus variant will spread the virus to
all neighboring points in the four cardinal directions (i.e. up, down, left, and right). If a cell has multiple variants, all the variants will spread without interfering with each other.
Given an integer k, return _theminimum integer number of days for
any point to contain at least _kof the unique virus variants.

Input: points =[[1,1],[6,1]], k =2Output: 3Explanation: On day 3, points (3,1) and (4,1) will contain both virus variants. Note that these are not the only points that will contain both virus variants.
Example 2:
1
2
3
4

Input: points =[[3,3],[1,2],[9,2]], k =2Output: 2Explanation: On day 2, points (1,3),(2,3),(2,2), and (3,2) will contain the first two viruses. Note that these are not the only points that will contain both virus variants.
Example 3:
1
2
3
4

Input: points =[[3,3],[1,2],[9,2]], k =3Output: 4Explanation: On day 4, the point(5,2) will contain all 3 viruses. Note that thisis not the only point that will contain all 3 virus variants.
For any point (x, y), the day it gets infected by a variant is the Manhattan distance to the variant’s origin. To have k variants at a point by day d, we need at least k origins within distance d. We can binary search the minimum d such that some point has at least k variants within d.
classSolution {
public:int minDays(vector<vector<int>>& points, int k) {
int n = points.size();
int l =0, r =200;
while (l < r) {
int d = (l + r) /2, found =0;
for (int x =0; x <=200; ++x) {
for (int y =0; y <=200; ++y) {
int cnt =0;
for (auto& p : points) {
if (abs(p[0]-x)+abs(p[1]-y) <= d) cnt++;
}
if (cnt >= k) { found =1; break; }
}
if (found) break;
}
if (found) r = d;
else l = d+1;
}
return l;
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
funcminDays(points [][]int, kint) int {
l, r:=0, 200forl < r {
d:= (l+r) /2found:=falseforx:=0; x<=200&& !found; x++ {
fory:=0; y<=200&& !found; y++ {
cnt:=0for_, p:=rangepoints {
ifabs(p[0]-x)+abs(p[1]-y) <=d { cnt++ }
}
ifcnt>=k { found = true }
}
}
iffound { r = d } else { l = d+1 }
}
returnl}
funcabs(aint) int { ifa < 0 { return-a } else { returna } }
classSolution {
publicintminDays(int[][] points, int k) {
int l = 0, r = 200;
while (l < r) {
int d = (l + r) / 2;
boolean found =false;
for (int x = 0; x <= 200 &&!found; x++) {
for (int y = 0; y <= 200 &&!found; y++) {
int cnt = 0;
for (int[] p : points) {
if (Math.abs(p[0]-x)+Math.abs(p[1]-y) <= d) cnt++;
}
if (cnt >= k) found =true;
}
}
if (found) r = d;
else l = d+1;
}
return l;
}
}
classSolution {
funminDays(points: Array<IntArray>, k: Int): Int {
var l = 0; var r = 200while (l < r) {
val d = (l + r) / 2var found = falsefor (x in0..200) {
for (y in0..200) {
var cnt = 0for (p in points) {
if (Math.abs(p[0]-x)+Math.abs(p[1]-y) <= d) cnt++ }
if (cnt >= k) { found = true; break }
}
if (found) break }
if (found) r = d else l = d+1 }
return l
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
classSolution:
defminDays(self, points: list[list[int]], k: int) -> int:
l, r =0, 200while l < r:
d = (l + r) //2 found =Falsefor x in range(201):
for y in range(201):
cnt = sum(abs(px-x)+abs(py-y) <= d for px,py in points)
if cnt >= k:
found =Truebreakif found: breakif found: r = d
else: l = d+1return l
impl Solution {
pubfnmin_days(points: Vec<Vec<i32>>, k: i32) -> i32 {
let (mut l, mut r) = (0, 200);
while l < r {
let d = (l + r) /2;
letmut found =false;
for x in0..=200 {
for y in0..=200 {
letmut cnt =0;
for p in points.iter() {
if (p[0]-x).abs()+(p[1]-y).abs() <= d { cnt +=1; }
}
if cnt >= k { found =true; break; }
}
if found { break; }
}
if found { r = d; } else { l = d+1; }
}
l
}
}
⏰ Time complexity: O(D * N * M) — D is the binary search range (up to 200), N is number of points, M is candidate points (up to 201*201). Acceptable for n ≤ 50.
🧺 Space complexity: O(1) — Only variables, no extra data structures.