2425. Number of People That Can Be Seen in a Grid

Medium
Array
Stack
Matrix
Monotonic Stack

Description

Hints

Hint 1
Imagine you are looking to the right. The heights of the people you see form an ascending sequence.
Hint 2
Iterate through the row from right to left. Use a decreasing monotonic stack to keep track of the people that you can see.
Hint 3
Use binary search to find the number of people in the stack that are shorter than the current person.
Hint 4
Repeat this process for each column.

Statistics

Acceptance
47.6%
Submissions
5,376
Accepted
2,557