Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Imagine you are looking to the right. The heights of the people you see form an ascending sequence.
Iterate through the row from right to left. Use a decreasing monotonic stack to keep track of the people that you can see.
Use binary search to find the number of people in the stack that are shorter than the current person.
Repeat this process for each column.