FastPrepSmallest Most-Lit Street Position

Smallest Most-Lit Street Position

Hudson River Trading logoHudson River Trading● MediumNEW GRADOA
Learn

Problem statement

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.

More Hudson River Trading problems

See Hudson River Trading hiring insights
public int mostLitPosition(int[] positions, int[] radii) {
    // Write your code here.
}
positions[0,5]
radii[2,3]
expected2
Checking account…