Skip to main content
Back to problems
Leetcode
Easy
Arrays
Greedy
Amazon
Can Place Flowers

Determine whether at least nn flowers can be planted in a flowerbed without placing any two flowers in adjacent plots.

Acceptance 0%
Problem Statement

You are given a binary array flowerbed where 0 means an empty plot and 1 means a plot already occupied by a flower. You may plant a flower only in an empty plot, and two flowers must never be placed in adjacent plots.

Return whether it is possible to plant at least n new flowers in the flowerbed while respecting the adjacency rule.

Input Format

  • flowerbed: an array of integers containing only 0 and 1
  • n: a non-negative integer

The flowerbed is treated as a one-dimensional line of plots.

Output Format

Return true if at least n flowers can be planted without violating the no-adjacent-flowers rule; otherwise return false.

Constraints

  • 1 <= flowerbed.length
  • Each flowerbed[i] is either 0 or 1
  • n >= 0
  • You may only plant in empty plots (0)
  • No two planted flowers may be adjacent
Examples
Sample cases returned by the problem API.

Example 1

Input

flowerbed = [1,0,0,0,1], n = 1

Output

true

Explanation

A flower can be planted in the middle empty plot, resulting in [1,0,1,0,1].

Example 2

Input

flowerbed = [1,0,0,0,1], n = 2

Output

false

Explanation

Only one valid planting position exists, so planting two flowers is impossible.

Show 1 more example

Example 3

Input

flowerbed = [0,0,1,0,0], n = 2

Output

true

Explanation

Flowers can be planted at the first and last plots: [1,0,1,0,1].

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.