Zepruv › Coding problems

Strange Printer II

Hard · Array, Graph, Topological Sort, Matrix

There is a strange printer with the following two special requirements:
You are given a m x n matrix targetGrid, where targetGrid[row][col] is the color in the position (row, col) of the grid.
Return true if it is possible to print the matrix targetGrid, otherwise, return false.

Example 1

Input: targetGrid = [[1,1,1,1],[1,2,2,1],[1,2,2,1],[1,1,1,1]]
Output: true

Example 2

Input: targetGrid = [[1,1,1,1],[1,1,3,3],[1,1,3,4],[5,5,1,4]]
Output: true

Example 3

Input: targetGrid = [[1,2,1],[2,1,2],[1,2,1]]
Output: false

It is impossible to form targetGrid because it is not allowed to print the same color in different turns.

Constraints

Starter code (python)

class Solution(object):
    def isPrintable(self, targetGrid):
        """
        :type targetGrid: List[List[int]]
        :rtype: bool
        """
        

Related problems

Previous: Maximum Sum Obtained of Any Permutation · Next: Replace All ?'s to Avoid Consecutive Repeating Characters · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.