Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Number of Visible Points

XPChallenge Points: 30
levelLevel: Hard

You are positioned at a fixed location on a 2D grid, facing east initially. You cannot move, but you may rotate freely.
You are given:

  • A list of point coordinates on the plane.

  • An integer that represents the width of your viewing cone in degrees.

  • A coordinate representing your current location.

For each point, consider the angle formed between the ray pointing east from your position and the ray from your position to that point.
A point is considered visible if its angle falls inside your viewing window when rotated optimally.

Points located exactly at your position are always visible.
Multiple points may share the same coordinates.
Visibility is not blocked by other points.

Your task is to determine the maximum number of points that can fit inside the viewing window after choosing the best rotation.

Example 1:

Input: points = [[4,2],[3,1],[5,3],[6,2]] ,angle = 60, location = [3,2]

Output: 3

Explanation:

With an optimal rotation, three of the points fall inside a 60° viewing range.

Example 2:

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

Output: 52

Explanation:

By rotating correctly, all four points can be included.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result