Best Sprinkler Coordinate for Maximum Coverage
Reported by candidates from Hudson River Trading's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
A sprinkler with an inclusive radius, a sorted array of flower coordinates, and a tie-break that wants the smallest coordinate. That's the Hudson River Trading OA reported in October 2026, and the details matter more than the idea. The core is a sliding window over a sorted array, with a twist in how you turn the best window into an actual coordinate. If you blank on that last step, StealthCoder is the safety net running invisibly during the live assessment. Otherwise, read on, because the whole thing fits in about fifteen lines.
The problem
You are given a strictly increasing integer array flowers containing flower coordinates on a number line and a nonnegative integer radius. Place one sprinkler at any integer coordinate c. It waters every flower whose coordinate lies in the inclusive interval [c - radius, c + radius]. Return a coordinate that waters the maximum possible number of flowers. If several coordinates water that maximum number, return the smallest such coordinate. Function bestSprinklerCoordinate(flowers: int[], radius: int) → int Examples Example 1 flowers = [-6,-1,0,8] radius = 4 return = -4 A sprinkler at -4 waters the three flowers at -6, -1, and 0. No position waters all four, and -4 is the smallest position that waters three. Example 2 flowers = [-3,2,3,4,9] radius = 2 return = 2 A sprinkler at 2 covers [0,4] and waters the three flowers at 2, 3, and 4. Example 3 flowers = [7] radius = 3 return = 4 Every sprinkler coordinate from 4 through 10 waters the only flower. The smallest valid coordinate is 4. Constraints 1 <= flowers.length <= 2 * 10^5. -10^9 <= flowers[i] <= 10^9. flowers is strictly increasing. 0 <= radius <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The sprinkler covers a span of width 2*radius. A set of flowers is covered together exactly when max - min <= 2*radius. So run two pointers over the sorted array. For each right index, advance left until flowers[right] - flowers[left] <= 2*radius, and track the largest window. The coordinate trick: for a window starting at flowers[left], the smallest valid c is flowers[right] - radius, since c + radius must reach the last flower. Take the smallest such c among windows tied for max count. Example 3 shows it: 7 - 3 = 4. Pitfalls: the answer is not a flower position, it can be negative, and ties must keep the earliest window. Use strict greater-than when updating the best. Values reach 10^9, so 2*radius hits 2*10^9, which overflows a 32-bit int in some languages. Use 64-bit. If the tie-break or overflow trips you mid-assessment, StealthCoder can hand you the corrected solution.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Best Sprinkler Coordinate for Maximum Coverage 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Hudson River Trading's OA.
Hudson River Trading reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Best Sprinkler Coordinate for Maximum Coverage FAQ
What's the trick in the Hudson River Trading sprinkler problem?+
Treat it as a sliding window on a sorted array. A group of flowers is coverable when the last minus the first is at most 2*radius. Find the largest such window, then convert it to a coordinate with flowers[right] - radius.
How do I get the smallest coordinate on ties?+
Only update your best when the window size is strictly greater. Since right moves left to right, the first window achieving the max has the smallest right end, so its coordinate flowers[right] - radius is the smallest. Don't use greater-or-equal.
Why is the answer flowers[right] - radius and not flowers[left]?+
The sprinkler reaches up to c + radius, so it must be at least flowers[right]. The smallest c satisfying that is flowers[right] - radius. Check example 1: window -6 to 0, so 0 - 4 = -4. That matches the expected output.
What edge cases break this solution?+
Radius 0, where each flower stands alone and you return the first flower. A single flower, where the answer is flower - radius. Negative coordinates. And overflow when computing 2*radius or differences near 10^9, so use 64-bit integers.
How do I prepare for this in 48 hours?+
Write the two-pointer window pattern from scratch twice on sorted input, with a tie-break rule. Then test your code on the three examples, plus radius 0 and a single flower. The complexity should be O(n) time and O(1) space given the sorted input.