FunctionRacerProblemsRace

Can Place Flowers

EasyGreedyPython, JavaScript, TypeScript, Java, C++

flowerbed is a row of plots, 0 for empty and 1 for planted. A new flower may only go into an empty plot whose neighbours (left and right, if they exist) are both empty.

Return True if n new flowers can all be planted, otherwise False.

Example 1

flowerbed [1,0,0,0,1]
n 1
returns true

Plant in the middle plot.

Example 2

flowerbed [1,0,0,0,1]
n 2
returns false

Only one more fits.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems