← Apple Interview Insights

Apple·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Apple SWE interview with a geometry-heavy coding problem that felt more like a math puzzle than anything I'd practiced. The question was deceptively clean on the surface but had a lot of edge cases hiding underneath.

Questions Asked (1)

Q1

You're standing at a fixed point on a hill surrounded by trees at various (x, y) coordinates. Given a viewing angle, find the maximum number of trees you can see in a single frame. Trees in the exact same direction only count once since closer ones block the rest.

Algorithms & Data Structures
Author's notes

The blocking condition is what tripped me up first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem by confirming that the viewing angle is centered on the observer and that trees in the same direction are blocked. Then, compute the angle of each tree relative to the observer, sort the angles, and use a sliding window to find the maximum number of unique angles within the given viewing angle.

Pro tip: Demonstrate attention to edge cases such as trees at the exact same angle (blocked) and the circular nature of angles (e.g., angles near 0 and 360 degrees). Also, discuss how to handle floating-point precision to avoid errors in angle comparisons.

1. Clarify the problem

Ask questions to confirm details: Is the viewing angle centered on the observer? Are trees considered points? Do trees at the same angle but different distances count as one? How to handle trees exactly on the boundary of the viewing angle?

2. Compute angles

For each tree, calculate the angle relative to the observer using atan2(dy, dx). Normalize angles to a consistent range (e.g., [0, 2π)).

3. Handle duplicates

Use a hash set or sort and deduplicate angles so that trees in the exact same direction are counted only once.

4. Sliding window over sorted angles

Sort the unique angles. Duplicate the array by adding 2π to each angle to handle circular wrap-around. Use a two-pointer sliding window to find the maximum number of angles within the viewing angle.

5. Return the maximum count

The size of the largest window is the answer. Discuss time complexity: O(n log n) due to sorting, and space complexity O(n).

Key Points to Mention

  • Angle calculation using atan2 to handle all quadrants correctly.
  • Deduplication of angles to account for blocking.
  • Circular handling by duplicating the sorted angles with +2π.
  • Sliding window (two-pointer) technique to find max within angle range.
  • Time and space complexity analysis.
  • Edge cases: no trees, all trees in same direction, viewing angle >= 360 degrees.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.