605. Can Place Flowers
#array
Given an integer array flowerbed
containing 0
's and 1
's, where 0
means empty and 1
means not empty, and an integer n
, return true
if n
new flowers can be planted in the flowerbed
without violating the no-adjacent-flowers rule and false
otherwise.
Intuition
We can plant a flower if both the adjacent plots are empty
Approach
Iterate over the array checking each plot and surrounding
If the plot is available for planting decrease the pending flower count and update the plot as planted.
Complexity
Space Complexity
Time Complexity
No extra space is used
We iterate over the array only once
Code
Last updated