Problem 2282 · Medium

Number of People That Can Be Seen in a Grid

Sweep every row and column with a monotonic stack; each person counts the taller-or-equal wall that stops the view.

Open the interactive visualisation