Smallest Most-Lit Street Position
Reported by candidates from Hudson River Trading's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The naive solution on this Hudson River Trading OA, reported October 2026, dies on the tie-break. Everyone finds the max overlap. Fewer people return the smallest position when several spots tie. This is a sweep line over inclusive intervals: each streetlight covers [p-r, p+r], and you need the leftmost point with peak coverage. With up to 200000 lights, brute force over positions is dead on arrival. If you blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net. Know the trick first, though.
The problem
A streetlight centered at positions[i] with radius radii[i] illuminates every integer position from positions[i] - radii[i] through positions[i] + radii[i], inclusive. Return the smallest integer position illuminated by the maximum number of streetlights. Function mostLitPosition(positions: int[], radii: int[]) → int Examples Example 1 positions = [0,5] radii = [2,3] return = 2 The two inclusive intervals overlap only at position 2. Example 2 positions = [1,4,7] radii = [3,0,3] return = 4 All three streetlights illuminate position 4. Example 3 positions = [0,10] radii = [1,1] return = -1 The maximum coverage is one in two disjoint intervals, so the smallest covered position is -1. Constraints 1 <= positions.length = radii.length <= 200000. -10^8 <= positions[i] <= 10^8. 0 <= radii[i] <= 10^8.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Turn each light into two events: +1 at p-r and -1 at p+r+1. The +1 on the end side is the inclusive-boundary trap. If you put -1 at p+r, you drop coverage one position too early and Example 2 breaks. Sort events by coordinate, apply all deltas at the same coordinate together, then check the running count. Only update the answer when the count is strictly greater than the best so far, which gives you the smallest position on ties. Process in coordinate order and you never need to scan integers. Values reach 10^8 plus 10^8, so coordinates fit in 32-bit signed ints, but use 64-bit if your language is shaky. Example 3 shows the other edge: disjoint intervals with equal coverage return the leftmost start. If you freeze on the event grouping during the live OA, StealthCoder is the hedge that surfaces the sweep and the p+r+1 fix.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Smallest Most-Lit Street Position 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.
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 for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Smallest Most-Lit Street Position FAQ
What's the trick in Smallest Most-Lit Street Position?+
Sweep line with difference events. Add +1 at p-r and -1 at p+r+1, sort, and walk through the coordinates keeping a running count. Record the position only when the count beats the best so far strictly. That strict comparison gives the smallest position automatically.
Why is the end event at p+r+1 and not p+r?+
The interval is inclusive, so the light still shines at p+r. The coverage drops starting at p+r+1. Put the decrement at p+r and you undercount that last position, which breaks Example 2 where all three lights meet at 4.
Can I just brute-force every integer position?+
No. Coordinates span roughly -2*10^8 to 2*10^8, and there can be 200000 lights. Checking each position against each light is far too slow. Sorting 400000 events is O(n log n) and fits easily.
How do I handle ties at the same coordinate?+
Group all events sharing a coordinate and apply their deltas together before comparing to the best. Since decrements sit at p+r+1, you won't get a false peak from processing a +1 before a -1 at the same point. Group first, then check.
How do I prepare for this Hudson River Trading OA in 48 hours?+
Write the sweep line once from scratch and test it on the three examples, especially the disjoint case returning -1. Then try random tiny inputs against a brute force. Also practice similar interval-overlap problems like meeting rooms II so the event pattern is automatic.