Rotate a View to See the Most Points

Quick Overview

Rotate a View to See the Most Points. An observer stays at location and may face any direction. A viewing sector has angular width angle degrees and includes both boundary rays. Count every point whose direction falls in the sector, with no obstruction by nearer points.

Rotate a View to See the Most Points

Company: Anduril

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem An observer stays at `location` and may face any direction. A viewing sector has angular width `angle` degrees and includes both boundary rays. Count every point whose direction falls in the sector, with no obstruction by nearer points. Points coincident with the observer are always visible, and duplicate coordinates count separately. Return the largest visible count. ```cpp class Solution { public: int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location); }; ``` ### Examples **Example 1:** ```text points = [[2,1],[1,2],[0,1],[1,1]], angle = 90, location = [1,1] Output: 3 Explanation: A sector can include the east and north rays, including both boundaries, plus the coincident point. ``` **Example 2:** ```text points = [[2,1],[3,1],[1,2]], angle = 0, location = [1,1] Output: 2 Explanation: The east ray contains two points even with zero angular width. ``` ### Constraints - `1 <= points.length <= 10^5`. - Each point and location has two integer coordinates. - `0 <= angle < 360`. - All x and y coordinates are in `[0,100]`. ### Clarifying Questions The observer may rotate freely but may not translate. The sector’s endpoints are inclusive; overlapping coordinates and coincident points retain multiplicity. ```hint Inspect the structure How should coincident points, duplicate coordinates, and points on either boundary ray contribute? ``` ### Reasoning checkpoints - Cover all facing directions without counting any point occurrence more than once. - Respect coincident points, duplicate coordinates, and inclusive sector boundaries in numerical comparisons. ### Optional extensions How would you return an optimal facing direction along with the count?

Overview: Rotate a View to See the Most Points. An observer stays at location and may face any direction. A viewing sector has angular width angle degrees and includes both boundary rays. Count every point whose direction falls in the sector, with no obstruction by nearer points.

Anduril logo
Anduril
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

An observer stays at location and may face any direction. A viewing sector has angular width angle degrees and includes both boundary rays. Count every point whose direction falls in the sector, with no obstruction by nearer points. Points coincident with the observer are always visible, and duplicate coordinates count separately. Return the largest visible count.

class Solution {
public:
    int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location);
};

Examples

Example 1:

points = [[2,1],[1,2],[0,1],[1,1]], angle = 90, location = [1,1]
Output: 3
Explanation: A sector can include the east and north rays, including both boundaries, plus the coincident point.

Example 2:

points = [[2,1],[3,1],[1,2]], angle = 0, location = [1,1]
Output: 2
Explanation: The east ray contains two points even with zero angular width.

Constraints

  • 1 <= points.length <= 10^5 .
  • Each point and location has two integer coordinates.
  • 0 <= angle < 360 .
  • All x and y coordinates are in [0,100] .

Clarifying Questions Guidance

The observer may rotate freely but may not translate. The sector’s endpoints are inclusive; overlapping coordinates and coincident points retain multiplicity.

Reasoning checkpoints

  • Cover all facing directions without counting any point occurrence more than once.
  • Respect coincident points, duplicate coordinates, and inclusive sector boundaries in numerical comparisons.

Optional extensions

How would you return an optimal facing direction along with the count?