LeetCode 1591: Strange Printer II

Problem Description

Explanation

To solve this problem, we need to check if it is possible to print the given targetGrid using the strange printer with the given constraints. We can do this by analyzing the colors in the grid and their relationships. If a color appears in a rectangle, it must not have been used before in any other rectangle.

We can iterate through the targetGrid and keep track of the color rectangles. If we encounter a color that has been used in a different rectangle, it is not possible to print the grid. Otherwise, we continue checking until the end of the grid.

Solutions

class Solution {
    public boolean isPrintable(int[][] targetGrid) {
        // Java solution code here
    }
}

Loading editor...