Find leftmost point of maximum brightness
Company: Uber
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates understanding of interval overlap counting, efficient use of ordered data structures for range events, tie-breaking logic, and robustness to numeric edge cases such as large coordinates and floating-point radii.
Constraints
- 0 <= n (number of lights)
- -1e9 <= p <= 1e9
- 0 <= r <= 1e9
- Intervals are closed: light [p, r] covers every x with p - r <= x <= p + r
- Two intervals that share only an endpoint coordinate DO overlap there
- Return the smallest coordinate achieving the maximum brightness; on an interval of maxima, return its left endpoint
- Return None / null for empty input
Examples
Input: ([[-2, 3], [1, 2]],)
Expected Output: -1
Explanation: Lamp [-2,3] lights [-5,1]; lamp [1,2] lights [-1,3]. They overlap on [-1,1] with brightness 2. The smallest such x is -1.
Input: ([[0, 1]],)
Expected Output: -1
Explanation: Single lamp lights [-1,1], brightness 1 everywhere on it. The leftmost point of the maximum is -1.
Hints
- Don't materialize the number line. Convert each lamp [p, r] into two events at coordinates p - r (start, +1) and p + r (end, -1).
- Sort events by coordinate. At ties, apply all starts (+1) before any ends (-1) so that intervals touching at a shared endpoint are counted as overlapping at that point.
- Sweep left to right tracking a running count. Each time the running count strictly exceeds the previous best, record the current coordinate as the answer — that coordinate is the left endpoint of the segment where the new maximum begins, which is exactly the smallest x with that brightness.
- Because you only update on a strict increase, the first (leftmost) coordinate that reaches the global maximum is returned automatically; later coordinates with equal brightness never overwrite it.