Flowerbed Capacity Queries
Reported by candidates from LinkedIn's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
A LinkedIn OA reported in September 2026 dresses up a classic as a query problem, and the setup is the trap. Up to 20,000 queries against a 20,000-length flowerbed means re-simulating planting per query is 400 million steps. The question is Flowerbed Capacity Queries, and the trick is that every query hits the same unchanged bed. Compute the max capacity once, then answer each query with one comparison. If you blank on the preprocessing idea during the live assessment, StealthCoder is the invisible safety net that surfaces it. Otherwise, you can write this in ten lines.
The problem
You are given a binary array flowerbed, where 1 means a plot already contains a flower and 0 means it is empty. The initial flowerbed is valid: no two occupied plots are adjacent. You are also given an integer array queries. For each queries[i], determine whether at least that many additional flowers can be planted without placing flowers in adjacent plots. Every query is independent. Evaluate each query against the same unchanged initial flowerbed; flowers considered for one query do not remain planted for another query. Return a boolean array answer where answer[i] is true exactly when queries[i] additional flowers can be planted. Preprocess the flowerbed once so that each query is answered in O(1) time. Function flowerbedCapacityQueries(flowerbed: int[], queries: int[]) → boolean[] Examples Example 1 flowerbed = [1,0,0,0,1] queries = [0,1,2] return = [true,true,false] The flowerbed has capacity for exactly 1 additional flower, at index 2. Therefore requests for 0 and 1 flowers succeed, while the request for 2 flowers fails. Example 2 flowerbed = [0,0,0,0,0] queries = [1,3,4] return = [true,true,false] Flowers can be placed at indices 0, 2, and 4, so the maximum additional capacity is 3. Example 3 flowerbed = [0] queries = [0,1,2] return = [true,true,false] The only plot can hold one flower. The independent queries compare 0, 1, and 2 with that capacity. Constraints 1 <= flowerbed.length <= 2 * 10^4 flowerbed[i] is either 0 or 1. The initial flowerbed contains no adjacent occupied plots. 1 <= queries.length <= 2 * 10^4 0 <= queries[i] <= flowerbed.length Queries are independent and do not mutate flowerbed.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is greedy. Scan left to right once. At each index i, if flowerbed[i] is 0 and both neighbors are 0 (treat out-of-bounds as 0), plant there, mark it as 1, and increment a counter. That counter is the max additional capacity. Then answer[i] = queries[i] <= capacity. That's the O(1) per query the prompt demands. The common pitfall is mutating the original array per query, which breaks independence and blows up runtime. Another is botching the edges, so test [0] and [0,0] by hand. Queries of 0 must return true, which the comparison handles automatically. Total work is O(n + q). If the greedy check feels shaky under pressure, StealthCoder is there as a hedge on the live OA, but the logic is short enough to hold in your head.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Flowerbed Capacity Queries cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as can place flowers. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass LinkedIn's OA.
LinkedIn reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Flowerbed Capacity Queries FAQ
What's the trick in Flowerbed Capacity Queries?+
Queries are independent and use the same unchanged bed, so the answer is just the maximum number of flowers you can add. Compute that once with a greedy scan, then each query is a single comparison against it. No per-query simulation needed.
Why does greedy planting give the true maximum?+
Planting at the earliest valid spot never blocks more future plots than any alternative. It only affects the next index, which you'd have to skip anyway. Taking the leftmost valid plot is optimal, the same reasoning as the classic Can Place Flowers problem.
How do I handle the edges of the array?+
Treat positions before index 0 and after the last index as empty. So index 0 only needs its right neighbor to be 0, and the last index only needs its left neighbor to be 0. Test the single-element input [0], which should give capacity 1.
What's the time complexity the OA expects?+
O(n) preprocessing for the greedy scan plus O(1) per query, so O(n + q) overall. With both n and q up to 20,000, anything that re-scans the bed per query is O(n*q) and will likely time out.
How do I prep for this LinkedIn OA in 48 hours?+
Write the greedy scan from memory twice, then wrap it in the query loop. Practice edge cases: all zeros, all ones-and-zeros alternating, single element, and query value 0. Then you've covered every example shape, and the whole thing is under 15 lines.