Find the most points a fixed observer can see within a rotating field of view

Quick Overview

An observer at a fixed point can rotate a field of view of a given width, and the task is to find the largest number of points visible at once. It tests turning coordinates into angles, handling wrap-around on a circle, points at the observer's own location, and inclusive boundaries under floating-point error.

Find the most points a fixed observer can see within a rotating field of view

Company: Aurora

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

You stand at `location = [pos_x, pos_y]` on the X-Y plane and are given a list `points`, where `points[i] = [x_i, y_i]`. All coordinates are integers. You start out facing due east. You cannot move, but you can rotate. Your field of view is `angle` degrees wide: if you rotate `d` degrees counterclockwise from east, you see every direction in the inclusive range `[d - angle/2, d + angle/2]`. You can see a point when the angle between the east direction and the ray from your position to the point falls inside your field of view. Several points can share a coordinate. Points at your own location are visible no matter how you rotate. Points never block the view of other points. Return the maximum number of points you can see at once. ### Function Signature ```python def visible_points(points: list[list[int]], angle: int, location: list[int]) -> int: ``` ### Rules - Every entry of `points` counts on its own, including repeated coordinates. - Both edges of the field of view are included. - Directions are measured counterclockwise from east and taken modulo 360 degrees, so a field of view can span the west direction (for example, 135 to 225 degrees). ### Constraints - `1 <= len(points) <= 10^5` - `len(points[i]) == 2` - `0 <= x_i, y_i <= 10^9` - `1 <= angle < 360` - `len(location) == 2` - `0 <= pos_x, pos_y <= 10^9` ### Examples ```text Input: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1] Output: 3 ``` Seen from (1, 1), the points lie at 0, 45 and 45 degrees. Facing 45 degrees gives the view from 0 to 90 degrees, which contains all three. ```text Input: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1] Output: 4 ``` The point [1,1] is at your location, so it is always visible. The other three lie at 0, 45 and about 56.3 degrees, so the same view from 0 to 90 degrees shows all four points. ```text Input: points = [[0,2],[0,0],[0,1],[2,1]], angle = 90, location = [1,1] Output: 3 ``` The points lie at 135, 225, 180 and 0 degrees. Facing west (180 degrees) shows the first three, from 135 to 225, and the point at 0 degrees is at least 135 degrees away from each of the others, so no view holds all four.

Overview: An observer at a fixed point can rotate a field of view of a given width, and the task is to find the largest number of points visible at once. It tests turning coordinates into angles, handling wrap-around on a circle, points at the observer's own location, and inclusive boundaries under floating-point error.

Aurora logo
Aurora
Nov 24, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

You stand at location = [pos_x, pos_y] on the X-Y plane and are given a list points, where points[i] = [x_i, y_i]. All coordinates are integers.

You start out facing due east. You cannot move, but you can rotate. Your field of view is angle degrees wide: if you rotate d degrees counterclockwise from east, you see every direction in the inclusive range [d - angle/2, d + angle/2].

You can see a point when the angle between the east direction and the ray from your position to the point falls inside your field of view. Several points can share a coordinate. Points at your own location are visible no matter how you rotate. Points never block the view of other points.

Return the maximum number of points you can see at once.

Function Signature

def visible_points(points: list[list[int]], angle: int, location: list[int]) -> int:

Rules

  • Every entry of points counts on its own, including repeated coordinates.
  • Both edges of the field of view are included.
  • Directions are measured counterclockwise from east and taken modulo 360 degrees, so a field of view can span the west direction (for example, 135 to 225 degrees).

Constraints

  • 1 <= len(points) <= 10^5
  • len(points[i]) == 2
  • 0 <= x_i, y_i <= 10^9
  • 1 <= angle < 360
  • len(location) == 2
  • 0 <= pos_x, pos_y <= 10^9

Examples

Input: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]
Output: 3

Seen from (1, 1), the points lie at 0, 45 and 45 degrees. Facing 45 degrees gives the view from 0 to 90 degrees, which contains all three.

Input: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]
Output: 4

The point [1,1] is at your location, so it is always visible. The other three lie at 0, 45 and about 56.3 degrees, so the same view from 0 to 90 degrees shows all four points.

Input: points = [[0,2],[0,0],[0,1],[2,1]], angle = 90, location = [1,1]
Output: 3

The points lie at 135, 225, 180 and 0 degrees. Facing west (180 degrees) shows the first three, from 135 to 225, and the point at 0 degrees is at least 135 degrees away from each of the others, so no view holds all four.