#1610
Maximum Number of Visible Points
master · 1830 · lc hard +32 · verified · 38% accepted · 625 likes · top 17%
Description
You are standing at location = [posx, posy] on a 2D plane, unable to move. Your field of view spans angle degrees. Given an array points of coordinates on the same plane, find the maximum number of points visible by choosing the optimal direction to look. Points at your exact location are always visible regardless of direction.
Example 1:
Input: points = [[2,1],[2,2],[3,3]], angle = 90, location = [1,1]
Output: 3
Explanation: The shaded region represents your field of view. All points can be made visible in your field of view, including [3,3] even though [2,2] is in front and in the same line of sight.
Example 2:
Input: points = [[2,1],[2,2],[3,4],[1,1]], angle = 90, location = [1,1]
Output: 4
Explanation: All points can be made visible in your field of view, including the one at your location.
Example 3:
Input: points = [[1,0],[2,1]], angle = 13, location = [1,1]
Output: 1
Explanation: You can only see one of the two points, as shown above.
Code
1
2
3