PIXELBANKv9.1.0
Menu

Given a flowerbed (array of 0s and 1s) and n new flowers, return True if n new flowers can be planted without violating the no-adjacent rule.

Example:

Input:
1,0,0,0,1
1
Output:
True
Reasoning:
  • The given flowerbed is represented as an array: [1,0,0,0,1], where 0 indicates an empty plot and 1 indicates a plot with a flower.
  • We need to plant 1 new flower, so we look for a plot where we can plant it without violating the no-adjacent rule.
  • We find that we can plant the new flower at the third plot: [1,0,0,1,1] or at other positions, but since we only need to plant 1 flower, we can choose any of these valid positions.
  • The final output is True because we can plant the new flower without violating the rule.

Constraints:

  • 1 <= len(flowerbed) <= 2 * 10^4
  • flowerbed[i] is 0 or 1
  • No two adjacent flowers exist in initial state
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Can Place Flowers - Easy | PixelBank