1016. Minimum Time For K Virus Variants to Spread

In an infinite 2D grid, there are n unique virus strains. Given a 2D array sources, where sources[i] = [xi, yi] represents a virus originating from (xi, yi) on day 0. Multiple viruses can originate from the same position.

Every day, each infected cell spreads its virus to the four cardinal directions (up, down, left, and right). If a cell already contains multiple virus strains, they continue to spread independently.

Given an integer k, return the minimum number of days required for any cell to contain at least k of the n unique virus strains.

Example 1:

Input: sources = [[2,2],[5,2]], k = 2

Output: 3

Explanation:

On day 3, locations like (3,2) and (4,2) will contain both virus strains. Other locations may also meet this condition.

Example 2:

Input: sources = [[4,4],[2,1],[8,1]], k = 2

Output: 3

Explanation:

On day 3, points (3,2), (2,3) will contain at least two virus strains.

Now Your Turn!

Pick the correct output for the given input

Input: sources = [[2,2],[4,1],[7,3]], k = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • n == sources.length
  • 2 ≤ n ≤ 50
  • sources[i].length == 2
  • 1 ≤ xi, yi ≤ 100
  • 2 ≤ k ≤ n

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int minDayskVariants(vector<vector<int>>& points, int k) {
}
};
 
Test Case

Input:

K
Sources