Check Whether More Flowers Fit without Adjacent Plants
Company: LinkedIn
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
flowerbed uses one for an existing flower and zero for an empty plot. Existing flowers are nonadjacent. Return whether n additional flowers can be planted so that no adjacent pair is occupied.
```cpp
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n);
};
```
### Examples
**Example 1:**
```text
flowerbed = [0,0,1,0,0], n = 2
Output: true
Explanation: Plant at both endpoints.
```
**Example 2:**
```text
flowerbed = [0,1,0,0], n = 2
Output: false
Explanation: Only the final plot can receive another flower.
```
### Constraints
- The bed has 1..20000 binary plots and begins without adjacent occupied plots. Requested new flowers n is in 0..flowerbed.length.
### Clarifying Questions
Preserve existing flowers and check both endpoint and newly created adjacency.
```hint Read the boundary condition
Can planting the leftmost currently valid plot ever reduce the best possible total?
```
### Contract considerations
Preserve existing flowers and check both endpoint and newly created adjacency.
Overview: Check Whether More Flowers Fit without Adjacent Plants. flowerbed uses one for an existing flower and zero for an empty plot.
Check Whether More Flowers Fit without Adjacent Plants
LinkedIn
Sep 12, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Problem
flowerbed uses one for an existing flower and zero for an empty plot. Existing flowers are nonadjacent. Return whether n additional flowers can be planted so that no adjacent pair is occupied.
class Solution {
public:
bool canPlaceFlowers(vector<int>& flowerbed, int n);
};
Examples
Example 1:
flowerbed = [0,0,1,0,0], n = 2
Output: true
Explanation: Plant at both endpoints.
Example 2:
flowerbed = [0,1,0,0], n = 2
Output: false
Explanation: Only the final plot can receive another flower.
Constraints
The bed has 1..20000 binary plots and begins without adjacent occupied plots. Requested new flowers n is in 0..flowerbed.length.
Clarifying Questions Guidance
Preserve existing flowers and check both endpoint and newly created adjacency.
Contract considerations
Preserve existing flowers and check both endpoint and newly created adjacency.