Minimum Time For K Virus Variants to Spread Problem
Description
LeetCode Problem 1956.
There are n unique virus variants in an infinite 2D grid. You are given a 2D array points, where points[i] = [x_i, y_i] represents a virus originating at (x_i, y_i) 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 the minimum integer number of days for any point to contain at least k of the unique virus variants.
Example 1:

Input: points = [[1,1],[6,1]], k = 2
Output: 3
Explanation: 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:

Input: points = [[3,3],[1,2],[9,2]], k = 2
Output: 2
Explanation: 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:

Input: points = [[3,3],[1,2],[9,2]], k = 3
Output: 4
Explanation: On day 4, the point (5,2) will contain all 3 viruses. Note that this is not the only point that will contain all 3 virus variants.
Constraints:
n == points.length2 <= n <= 50points[i].length == 21 <= x_i, y_i <= 1002 <= k <= n
Solution
Approach: Enumerate the meeting cell
A cell (x, y) holds k variants on day t exactly when at least k origins are within Manhattan distance t of it. So the best day for that cell is the k-th smallest Manhattan distance from the cell to the origins, and the answer is the minimum of this value over all cells.
We only need cells inside the box [1, 100] x [1, 100]: moving a cell into the box never increases its distance to any origin, since every origin lies in the box. For each of these 10^4 cells we compute the distances to the n origins and take the k-th smallest.
Complexity: O(M^2 * n log n) time with M = 100 the coordinate bound, and O(n) space.
class Solution:
def minDayskVariants(self, points: List[List[int]], k: int) -> int:
ans = 1 << 30
for x in range(1, 101):
for y in range(1, 101):
d = sorted(abs(x - a) + abs(y - b) for a, b in points)
ans = min(ans, d[k - 1])
return ans