Can Place Flowers
EasyGreedy
Decode it first. Clues, constraints, pattern and plan before any code.A flowerbed is a row of plots: 1 is planted, 0 is empty. Flowers may not be planted in adjacent plots. The bed you are given already follows that rule. Return true if you can plant n new flowers without breaking it.
flowerbed = [1, 0, 0, 0, 1], n = 1 → true
flowerbed = [1, 0, 0, 0, 1], n = 2 → false
flowerbed = [0, 0, 1, 0, 0], n = 2 → true (both ends)Constraints
1 <= flowerbed.length <= 2 * 10^4flowerbed[i]is0or1.- No two adjacent plots are both
1. 0 <= n <= flowerbed.length