Minimum Time For K Virus Variants to Spread — LeetCode 1956 Python Solution
- Problem
- #1956
- Pattern
- Monotonic Stack
- Reading time
- 2 min
- Source
- leetcode.com
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
| Measure | Complexity |
|---|---|
| Time | O(log n) or O(n log n) |
| Space | O(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.