Problem 04 of 75

Can Place Flowers

EasyNot solved yetInterview me on this
Before you code · which pattern fits?

The problem

You have a flowerbed in which some plots are planted (1) and some are not (0). Flowers cannot be planted in adjacent plots.

Given the flowerbed array and an integer n, return true if n new flowers can be planted without violating the no-adjacent-flowers rule.

([1,0,0,0,1], 1) → true ([1,0,0,0,1], 2) → false

Your solution runs against 3 unit tests, including edge and large-value cases.

Loading...

Test console · 3 unit tests

Submit your code to run it against all 3 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.

Hint

Reference solution

Video explanation

Can Place Flowers, explainedNeetCode