Ctrl K

Where Moss Species Meet

Hard
Colonies of moss grow on an infinite grid, each colony a different species. Colony i occupies cell colonies[i] = [x, y] on day 0; several colonies may start in the same cell. Every day each species spreads from every cell it occupies into the four neighbouring cells (up, down, left and right). Species do not interfere with each other, so a cell can host any number of them. Return the smallest whole number of days after which some cell holds at least k different species.
Example 1
colonies=[[2, 2], [2, 7]], k=2 → 3

The two colonies are 5 cells apart in the same column. After 3 days cell (2, 5) is reached by both: it is 3 steps from the first and 2 from the second. After 2 days the areas do not overlap yet.

Example 2
colonies=[[1, 1], [5, 1], [3, 9]], k=2 → 2

The first two colonies are the closest pair, 4 steps apart, so after 2 days cell (3, 1) holds both species.

Example 3
colonies=[[4, 4], [4, 4], [10, 10]], k=2 → 0

Two species start in the same cell, so the answer is 0.

Constraints
  • 2 ≤ len(colonies) ≤ 50
  • colonies[i] = [x, y], 1 ≤ x, y ≤ 100
  • 2 ≤ k ≤ len(colonies)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCorner Pairs With No One Between HardGrid Points Under Circles MediumEmpty Boxes Between Points MediumEmpty Rectangle From Marked Points MediumStars on One Straight Line Hard
loading Python…
Input
colonies=[[2, 2], [2, 7]], k=2
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 212 tests on the server, hidden ones included.