Reported August 2026
Capital Onesliding window

Optimal Lamp Coordinate

Reported by candidates from Capital One's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capital One OA. Under 2s to a working solution.
Founder's read

Capital One reported this one in August 2026, and it looks fancier than it is. Lamps, number lines, inclusive intervals. Strip the story and it's a sorted array with a window of width 2*radius. You need the window that holds the most objects, then the smallest lamp coordinate that realizes it. The array is already strictly increasing, so there's no sorting step. If you've got an OA invite for this, the pattern is sliding window with two pointers, and the only real trap is the tie-break. StealthCoder sits invisibly in the corner as a safety net if your mind goes blank mid-assessment.

The problem

You are given a strictly increasing integer array objects containing the coordinates of objects on a number line, and a nonnegative integer radius.
Place one lamp at any integer coordinate c. The lamp illuminates every object whose coordinate lies in the inclusive interval [c - radius, c + radius].
Return a coordinate that illuminates the maximum possible number of objects. If several coordinates illuminate that maximum number, return the smallest such coordinate.

Function
optimalLampCoordinate(objects: int[], radius: int) → int

Examples
Example 1
objects = [-5,3,4,9]
radius = 5
return = -1
A lamp at -1 illuminates the objects at -5, 3, and 4. No coordinate can illuminate all four objects. Other coordinates can also illuminate three objects, but -1 is the smallest one that does so.
Example 2
objects = [1,2,8]
radius = 1
return = 1
A lamp at 1 covers the inclusive interval [0,2], illuminating the first two objects. No lamp can illuminate all three, and 1 is the smallest coordinate that illuminates two.
Example 3
objects = [7]
radius = 3
return = 4
Every lamp coordinate from 4 through 10 illuminates the only object. The smallest valid coordinate is 4.

Constraints
1 <= objects.length <= 2 * 10^5
-10^9 <= objects[i] <= 10^9
objects is strictly increasing.
0 <= radius <= 10^9

Reported by candidates. Source: FastPrep

Pattern and pitfall

A lamp at c covers [c - r, c + r]. Two objects a < b fit under one lamp only if b - a <= 2r. So slide a right pointer across the array and move the left pointer forward while objects[right] - objects[left] > 2*radius. Track the max window size. The best lamp for a window starting at objects[left] is c = objects[right] - radius, the smallest c that still reaches the rightmost object. Check example 1: window -5, 3, 4 gives 4 - 5 = -1. Correct. Update the answer only on a strictly larger count, since earlier windows have smaller coordinates. Pitfalls: using the left object plus radius instead of the right minus radius, and overflow in 2*radius with 32-bit ints (use long). It's O(n). If you freeze on the tie-break during the live OA, StealthCoder can surface the logic without the proctor seeing it.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Optimal Lamp Coordinate 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Capital One's OA.

Capital One reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Optimal Lamp Coordinate FAQ

What's the trick in Optimal Lamp Coordinate?+

It's a sliding window on a sorted array. Any set of objects fits under one lamp if the max minus the min is at most 2*radius. Find the largest such window, then compute the smallest lamp coordinate for it: rightmost object minus radius.

How do I get the smallest coordinate on ties?+

For each window, the smallest valid lamp is objects[right] - radius. Only replace your best answer when the window count is strictly larger. Windows are scanned left to right, so earlier ones have smaller coordinates and win ties automatically.

Do I need to sort the array?+

No. The problem says objects is strictly increasing, so sorting is wasted work. Go straight to two pointers. With up to 2*10^5 elements, an O(n log n) or O(n) solution is fine, but O(n^2) brute force over coordinates will not pass.

Are there overflow risks here?+

Yes. Coordinates reach 10^9 in magnitude and radius reaches 10^9, so 2*radius or differences can exceed the 32-bit range. Use 64-bit integers for the comparison and the coordinate math, then return the result as the expected int type.

How do I prepare for this in 48 hours?+

Write the fixed-width sliding window on a sorted array twice from scratch. Then hand-trace the three examples, especially example 3 where a single object returns 4, which is object minus radius. That covers the edge cases this problem tests.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capital One.

OA at Capital One?
Invisible during screen share
Get it