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.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.
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.
colonies=[[4, 4], [4, 4], [10, 10]], k=2 → 0
Two species start in the same cell, so the answer is 0.
colonies=[[2, 2], [2, 7]], k=2
3
Run checks the first 3 tests in your browser. Submit checks all 212 tests on the server, hidden ones included.