Can Place Flowers
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
1 <= len(flowerbed) <= 300 <= n <= len(flowerbed)- The starting flowerbed has no two planted plots side by side.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.