A long flowerbed is given as an array of 0s (empty plot) and 1s (planted plot). Flowers cannot be planted in adjacent plots. Given the flowerbed and an integer n, return true if n new flowers can be planted without breaking the no-adjacent-flowers rule, and false otherwise.
A long flowerbed is given as an array of 0s (empty plot) and 1s (planted plot). Flowers cannot be planted in adjacent plots. Given the flowerbed and an integer n, return true if n new flowers can be planted without breaking the no-adjacent-flowers rule, and false otherwise.
Example 1:
Input: {"flowerbed":[1,0,0,0,1],"n":1}
Output: true
Constraints:
1≤flowerbed.length≤2×104
flowerbed[i] is 0 or 1.
There are no two adjacent flowers in flowerbed.
0≤n≤flowerbed.length
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"flowerbed":[1,0,0,0,1],"n":1}
We need to fit 1 new flower. Walk the bed left to right and plant in every empty plot whose neighbors are both empty.