Minimum Time For K Virus Variants to Spread — LeetCode 1956 Python Solution

HardLeetCode PremiumGeometryArrayMathBinary SearchEnumeration
Problem
#1956
Reading time
2 min

The problem

There are n unique 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.

Example

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.

Complexity

MeasureComplexity
TimeO(log n) or O(n log n)
SpaceO(1) auxiliary

Pattern: Monotonic Stack

Answer "what is the next greater element" for every position in one pass. LeetCode 1956. Minimum Time For K Virus Variants to Spread is filed here because the reference solution below belongs to the algorithm family this hub collects, even though its LeetCode tags point elsewhere.

The monotonic stack guide has the Python template for the pattern and the 225 LeetCode problems that use it.

Related problems

Frequently asked questions

How hard is LeetCode 1956. Minimum Time For K Virus Variants to Spread?
LeetCode 1956. Minimum Time For K Virus Variants to Spread is rated Hard on LeetCode.
What topics does LeetCode 1956. Minimum Time For K Virus Variants to Spread cover?
LeetCode 1956. Minimum Time For K Virus Variants to Spread is tagged Geometry, Array, Math, Binary Search and Enumeration on LeetCode.
Is LeetCode 1956. Minimum Time For K Virus Variants to Spread a premium problem?
Yes. LeetCode 1956. Minimum Time For K Virus Variants to Spread is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview