Count Coordinates Illuminated by Exactly One Lamp
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The TikTok OA reported in September 2026 looks like a lamp problem, but it's really interval coverage counting. Each lamp becomes a closed integer interval, and you want the total length of points covered exactly once. With up to 100000 lamps and coordinates near 10^9, brute force over the line is dead on arrival. You need a sweep. If you blank on the event setup during the live assessment, StealthCoder sits invisibly on your screen as a safety net and hands you the approach. Know the trick first and you won't need it.
The problem
There are lamps on an integer coordinate line. Each row lamps[i] = [coordinate, radius] describes one lamp. The lamp illuminates every integer coordinate in the inclusive interval from coordinate - radius through coordinate + radius. Return the number of integer coordinates illuminated by exactly one lamp. Return the count as a 64-bit integer. Function solution(lamps: int[][]) → long Examples Example 1 lamps = [[-2,3],[2,3],[2,1]] return = 6 The three intervals are [-5,1], [-1,5], and [1,3]. Exactly one lamp illuminates coordinates -5, -4, -3, -2, 4, and 5. Example 2 lamps = [[-2,1],[2,1]] return = 6 The disjoint intervals are [-3,-1] and [1,3]. All six illuminated integer coordinates have coverage exactly one. Constraints For this exercise, assume 1 <= lamps.length <= 100000. For this exercise, assume -10^9 <= lamps[i][0] <= 10^9. For this exercise, assume 1 <= lamps[i][1] <= 10^9.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Turn each lamp [c, r] into two events: +1 at c - r, and -1 at c + r + 1. The +1 end makes the interval half-open, which handles inclusive integer endpoints cleanly. Sort all events by position, then sweep. Between consecutive event positions, the coverage count is constant. If the running count equals exactly 1, add the gap length (next position minus current position) to the answer. Apply all events at the same position before measuring the next gap. The pitfalls are the off-by-one on the right end, forgetting to group same-position events, and overflow. Use a 64-bit integer, since the total can reach about 2 * 10^9 times many lamps' span. Sorting gives O(n log n), which fits 100000 lamps easily. If the sweep logic slips under pressure, StealthCoder can supply the event-sorting template during the live OA.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Count Coordinates Illuminated by Exactly One Lamp 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 by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Coordinates Illuminated by Exactly One Lamp FAQ
What's the trick to the exactly-one-lamp problem?+
Convert each lamp to a +1 event at c - r and a -1 event at c + r + 1. Sort events, sweep, and add the gap length whenever the running coverage equals 1. It's a difference-array idea on sparse coordinates, since the line is too large to scan directly.
Why use c + r + 1 for the end event?+
Intervals are inclusive on both ends over integers. Ending the +1 at c + r + 1 turns it into a half-open range, so the gap between positions equals the exact count of integer points. Without the +1, you undercount by one per segment and fail example 1.
Do I need a 64-bit integer here?+
Yes. Coordinates range up to 10^9 with radii up to 10^9, so a single interval can span about 2 * 10^9 points, which overflows a 32-bit int. The problem even asks for a long return. Use long in Java or C++, and Python handles it natively.
How hard is this TikTok OA question really?+
Medium. The sweep line is standard, but the inclusive endpoints and same-position events trip people up. If you've seen meeting rooms or merge intervals style event sorting, this is a small step further. The hard part is staying careful with off-by-ones.
How do I prepare for this in 48 hours?+
Write the sweep once from scratch on both examples and hand-check them. Then test edge cases: identical lamps, touching intervals, and a single lamp. Make sure you sort events by position and apply all deltas at one position together before measuring the next gap.