Leetcode #1610: Maximum Number of Visible Points
In this guide, we solve Leetcode #1610 Maximum Number of Visible Points in Python and focus on the core idea that makes the solution efficient.
You will see the intuition, the step-by-step method, and a clean Python implementation you can use in interviews.

Problem Statement
You are given an array points, an integer angle, and your location, where location = [posx, posy] and points[i] = [xi, yi] both denote integral coordinates on the X-Y plane. Initially, you are facing directly east from your position.
Quick Facts
- Difficulty: Hard
- Premium: No
- Tags: Geometry, Array, Math, Sorting, Sliding Window
Intuition
We are looking for a contiguous region that satisfies a constraint, which is a classic sliding-window signal.
Expanding and shrinking the window lets us maintain validity without restarting the scan.
Approach
Grow the window with a right pointer, and shrink from the left only when the constraint is violated.
Track the best window as you go to keep the solution linear.
Steps:
- Expand the right end of the window.
- While invalid, move the left end to restore constraints.
- Update the best window found.
Example
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.
Python Solution
class Solution:
def visiblePoints(
self, points: List[List[int]], angle: int, location: List[int]
) -> int:
v = []
x, y = location
same = 0
for xi, yi in points:
if xi == x and yi == y:
same += 1
else:
v.append(atan2(yi - y, xi - x))
v.sort()
n = len(v)
v += [deg + 2 * pi for deg in v]
t = angle * pi / 180
mx = max((bisect_right(v, v[i] + t) - i for i in range(n)), default=0)
return mx + same
Complexity
The time complexity is O(n). The space complexity is O(1) to O(n).
Edge Cases and Pitfalls
Watch for boundary values, empty inputs, and duplicate values where applicable. If the problem involves ordering or constraints, confirm the invariant is preserved at every step.
Summary
This Python solution focuses on the essential structure of the problem and keeps the implementation interview-friendly while meeting the constraints.