Skip to main content

Maximum Number of Visible Points

HardPremium

You're standing at location on a 2D grid, and points lists the coordinates of points around you. Your field of view is angle degrees wide. You can turn to face any direction, but you can't move.

If you face direction d, you can see every point whose direction from you is within angle / 2 degrees of d, including points exactly on the edges. Points don't block each other, and a point at your own location is always visible. Return the largest number of points you can see at once.

Example 1

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

The three points are at 0, 45 and 45 degrees from you, so a 90-degree view can cover all of them.

Example 2

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

[1, 1] is at your location, so it's always visible. The other three fit in one 90-degree view.

Constraints

  • 1 <= points.length <= 100000
  • 0 <= angle < 360
  • All coordinates are integers between 0 and 100.