Algorithms & Data Structuresmedium
Count Pins on a Two-Column Screen
The home feed is two columns of pins. Each pin is (top, bottom, column) with top < bottom and column "L" or "R"; pins in the same column never overlap. The screen shows a vertical window of length screenLen, scrolled to any offset. Return the maximum number of pins fully visible at once.
pins = [(1,4,"L"), (2,3,"R"), (4,8,"R"), (6,9,"L")], screenLen = 5 => 2 window [1,6] shows (1,4,L) and (2,3,R); window [4,9] shows (4,8,R) and (6,9,L)
Up to 100,000 pins; coordinates up to 10^9 and possibly fractional; input unsorted.
Follow-ups
- Return the scroll offset that achieves the maximum.
- K columns instead of two.
- Count pins with any overlap instead of full visibility — which technique replaces this one? (A +1/−1 sweep.)