The key insight is converting each point to its polar angle relative to the origin, then running a sliding window over the sorted angle list to find the window of size equal to the cone's angle that contains the most points.
Model the problem as finding the maximum number of points within an angular window of fixed width. Convert each point to an angle relative to the origin, sort the angles, and use a sliding window (two-pointer) technique to find the maximum count within any window of that width, handling circular wrap-around by duplicating the array with +2π offsets.
Pro tip: Clarify whether the cone's boundaries are inclusive and whether points exactly on the boundary count; also discuss how to handle points at the origin or with identical angles, as these edge cases often trip up candidates.
Ask about the number of points, whether the origin is fixed, if the cone's angular width is given, and if boundary points are included. This ensures you solve the correct problem.
For each point (x, y), compute its angle θ = atan2(y, x) in radians. This reduces the 2D problem to a 1D angular problem.
Sort the angles in ascending order. To handle wrap-around, duplicate the sorted list by adding 2π to each angle, creating a circular array of length 2n.
Use two pointers to maintain a window of angles within the cone's angular width. Expand the right pointer and shrink the left when the difference exceeds the width, tracking the maximum count.
The maximum count is the answer. The direction can be the angle at the left pointer (or the midpoint of the window) that achieves this maximum.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.