Connected Crop Garden
Problem statement
Plant k crop types in a garden. Crop IDs are 1..k, and counts[i] is the exact number of cells required for crop i + 1. Every crop must occupy one nonempty region connected through shared edges; diagonal contact alone does not connect cells.
The garden has one of two shapes:
- When
stackedSquaresisfalse, it is ann-row,m-column rectangle. - When
stackedSquaresistrue, ann x nsquare sits immediately above anm x msquare, both starting at column0. The shape hasn + mrows.
Return the following canonical connected allocation. Visit actual garden cells one row at a time from top to bottom:
Examples
Example 1
n = 2m = 3stackedSquares = falsecounts = [2,3,1]return = [[1,1,2],[3,2,2]]Visit the top row from left to right and the bottom row from right to left. The three crop blocks contain 2, 3 and 1 cells; each block is connected.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.