As reported: Google Software Engineer, University Graduate 2025, round 4 (India, January 2025, 45 minutes of coding): given a rectangular PCB board with
ncomponents, find the maximum number of components that a single straight line — horizontal or vertical — can touch.
A board is W × H. Component i occupies the axis-aligned rectangle from (x1, y1) to (x2, y2) (x1 ≤ x2, y1 ≤ y2; a component may be a single point). A vertical line x = c touches component i if x1 ≤ c ≤ x2; a horizontal line y = c touches it if y1 ≤ c ≤ y2 — edges count.
Return the largest number of components touched by one horizontal or vertical line.
Example 1
board 10 × 10, components (x1,y1,x2,y2):
(1,1,2,2) (2,5,3,6) (5,1,6,2) (8,8,8,8) (0,2,0,4)
-> 3 the line y = 2 touches the first, third and fifth
Vertically, x = 2 touches only two ([1,2] and [2,3]).
Example 2
board 5 × 5, components (1,1,1,1) and (3,3,3,3) -> 1
Constraints: 1 ≤ n ≤ 10^5; 0 ≤ x1 ≤ x2 ≤ W ≤ 10^9; 0 ≤ y1 ≤ y2 ≤ H ≤ 10^9; components may overlap.
Code runner format: the first line is W H n, then n lines x1 y1 x2 y2. Implement maxTouched(W, H, components); the harness prints the result.