Problem 1591 · Hard

Strange Printer II

Build a must-paint-before graph from each color's bounding rectangle and check that it has no cycle.

Open the interactive visualisation