FastPrepGarden Sprinkler Placement
Problems/Garden Sprinkler Placement

Garden Sprinkler Placement

Airbnb logoAirbnb● MediumINTERNOA

Updated Dec 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Airbnb intern online assessment. The task is to place one sprinkler on a straight garden path so it waters the most flowerbeds, and to pick the smallest spot when there is a tie.

The limit on radius was cut off in the screenshots. Here, radius is between 0 and 10^9.

Our version is about 98% the same as the reported question.

Special thanks: Thanks to an incredible friend for sharing this question with FastPrep.

Given an integer array flowerbeds and an integer radius, return the coordinate where one sprinkler waters the most flowerbeds. If several coordinates water the same largest number of flowerbeds, return the smallest such coordinate.

A garden is laid out along a single straight path. Each flowerbed sits at its own distinct integer coordinate on this path, and flowerbeds lists these coordinates sorted in increasing order.

You have exactly one sprinkler to install. It can go at any integer coordinate along the path, even directly on top of a flowerbed. A sprinkler installed at coordinate c waters every flowerbed whose coordinate is in the range [c - radius, c + radius], including both ends.

Function

solution(flowerbeds: int[], radius: int) → int

Examples

Example 1

flowerbeds = [-6,-1,0,8]radius = 4return = -4

Watering all four flowerbeds is impossible, because the leftmost and rightmost sit 14 units apart, farther than twice the radius. The three flowerbeds at -6, -1, and 0 can be watered together, though. The sprinkler may be installed anywhere from -4 through -2, and the smallest of those coordinates is -4.

Example 2

flowerbeds = [-3,2,3,4,9]radius = 2return = 2

Watering all five flowerbeds isn't possible either, since the leftmost and rightmost are 12 units apart. The best achievable is watering three flowerbeds, 2, 3, and 4, by installing the sprinkler anywhere from 2 through 4. The smallest of those coordinates is 2.

Constraints

  • 1 <= flowerbeds.length <= 2 * 10^5
  • -10^9 <= flowerbeds[i] <= 10^9
  • flowerbeds[i] < flowerbeds[i + 1]
  • 0 <= radius <= 10^9

More Airbnb Online Assessment questions

  • Bouncing DiagonalsOA · Seen Dec 2026
  • Count Numbers Not Equal to the First TwoOA · Seen Dec 2026
  • Theme Park Shuttle Wait TimeOA · Seen Dec 2026
  • Count Card Duel RoundsOA · Seen Nov 2026
  • Count Lamps Lighting Each PointOA · Seen Nov 2026
  • Simulate Orchard Rot SpreadOA · Seen Nov 2026
  • Sort Adjacent PairsOA · Seen Nov 2026
  • In-Memory File SystemOA · Seen Nov 2026
  • Task Management SystemOA · Seen Nov 2026
  • Recipe Management SystemOA · Seen Nov 2026

Similar questions at other companies

  • Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Maximum Consecutive Sum Within a ThresholdIndeed · OAIndeed interview questions
  • Fastest Average Speed over a Rolling KilometerOptiver · OAOptiver interview questions
  • Maximum Requests in a Time WindowIBM · OAIBM interview questions
  • Maximum Events in a 60-Second WindowMarshall Wace · OAMarshall Wace interview questions
  • Subarray Product Less Than KApple · PHONE SCREENApple interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Subarray Product Less Than KAngel One · PHONE SCREEN
  • Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions

Airbnb interview experiences

  • Airbnb OA · November 2026
  • Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
  • Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
  • Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
  • Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
  • Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public int solution(int[] flowerbeds, int radius) {
        // Write your solution here.
    }
}
Checking account…