FastPrepCount Coordinates Illuminated by Exactly One Lamp

Count Coordinates Illuminated by Exactly One Lamp

TikTok logoTikTok● MediumFULLTIMEOA
Learn

Problem statement

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.

More TikTok problems

See TikTok hiring insights
public long solution(int[][] lamps) {
    // Write your code here.
}
lamps[[-2,3],[2,3],[2,1]]
expected6
Checking account…