As reported: Google L4 onsite coding round (January 2025): trees in a forest at coordinates
(x, y); a camera with a fixed visibility angle (between 0 and 360 degrees) can only be placed at the origin; a predefined function gives the angle each tree makes with the x-axis (0–360). Return a list of minimum size of the angles at which to point the camera so that all trees are captured. Examples: trees(1,0), (2,1), (3,1)with angle 90 →[0]; trees(1,1), (1,−1)with angle 90 →[315].
A camera at the origin pointed at direction a (degrees, counter-clockwise from the positive x-axis) captures every tree whose angle lies in [a, a + fov], going counter-clockwise and wrapping past 360. The angle of a tree at (x, y) is atan2(y, x) converted to degrees in [0, 360).
Given the trees and fov, return a list of directions of minimum size such that every tree is captured by at least one of them.
Example 1
trees = (1,0) (2,1) (3,1), fov = 90 -> [0] angles 0°, 26.6°, 18.4°
Example 2
trees = (1,1) (1,-1), fov = 90 -> [315] 315° … 405° = 45° covers both
Clarifications
- A tree exactly on the edge of the view is captured.
- No tree is at the origin; several trees may share an angle.
- Any list of minimum size that captures every tree is accepted; directions may be any real numbers (they are taken modulo 360).
Constraints: 1 ≤ n ≤ 1000; |x|, |y| ≤ 10^9; 1 ≤ fov ≤ 359 (an integer).
Code runner format: the first line is n fov, then n lines x y. Implement cameraDirections(trees, fov) returning the directions in degrees. The harness checks that your list has the minimum size and captures every tree (with a tolerance of 10^-6 degrees), and prints OK or what is wrong.