FastPrepConnected Crop Garden

Connected Crop Garden

Google logoGoogle● MediumNEW GRADFULLTIMEPHONE SCREENONSITE INTERVIEW

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 stackedSquares is false, it is an n-row, m-column rectangle.
  • When stackedSquares is true, an n x n square sits immediately above an m x m square, both starting at column 0. The shape has n + m rows.

Return the following canonical connected allocation. Visit actual garden cells one row at a time from top to bottom:

The problem statement continues
Pro

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.

FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week