Back to problems

Connected Crop Arrangement on a Grid

Algorithm · Google · Hard

Requirements You are planting a garden laid out as a grid with N rows and M columns. There are K crop types, labeled from 1 to K, and crop i has to be planted in exactly count[i] cells. It is guaranteed that sum(count) = N * M, so no cell is left empty. For each crop type, all cells holding that crop must make up a single connected region. Two cells are neighbors only if they share an edge (up, down, left, or right); diagonal contact does not connect cells. Different crop…

Loading the rest of the question…