Strange Printer II — LeetCode 1591 Python Solution
- Problem
- #1591
- Pattern
- Topological Sort
- Reading time
- 2 min
- Source
- leetcode.com
The problem
There is a strange printer with the following two special requirements: On each turn, the printer will print a solid rectangular pattern of a single color on the grid. This will cover up the existing colors in the rectangle.
Example
- Input
- targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]
- Output
- true
Complexity
| Measure | Complexity |
|---|---|
| Time | O(V+E) |
| Space | O(V) auxiliary |
Pattern: Topological Sort
Order a set of tasks so that every dependency comes before the thing that needs it. LeetCode 1591. Strange Printer II is filed here because LeetCode tags it Topological Sort, which is the vocabulary this hub collects.
The topological sort guide has the Python template for the pattern and the 32 LeetCode problems that use it.
Related problems
Frequently asked questions
- How hard is LeetCode 1591. Strange Printer II?
- LeetCode 1591. Strange Printer II is rated Hard on LeetCode.
- What is the time complexity of LeetCode 1591. Strange Printer II?
- The Python solution on this page runs in O(V+E).
- What is the space complexity of LeetCode 1591. Strange Printer II?
- The Python solution on this page uses O(V) auxiliary space.
- What topics does LeetCode 1591. Strange Printer II cover?
- LeetCode 1591. Strange Printer II is tagged Graph, Topological Sort, Array and Matrix on LeetCode.