Directional beam coverage

Write codeMedium20 min

Your task

A rooftop hub aims directional beams at relay towers. Tower i sits east[i] metres east and north[i] metres north of the hub, and negative values mean west or south. One beam covers a whole ray leaving the hub, so towers lying in the same direction share a beam however far out they are, while a tower in the exactly opposite direction needs a beam of its own. A tower recorded at the hub itself, zero east and zero north, is mounted on the hub and needs no beam. Given the two offset lists, which have the same length, return how many beams the hub must install so that every tower is covered.

Examples

beams_needed(east: list[int], north: list[int]) -> int
Example 1
Inputbeams_needed([1, 2, 3], [2, 4, 6])
Output1
Example 2
Inputbeams_needed([1, -1, 0, 0], [0, 0, 1, -1])
Output4
Example 3
Inputbeams_needed([0, 3], [0, 0])
Output1