java.lang.Object
g1901_2000.s1944_number_of_visible_people_in_a_queue.Solution

public class Solution extends Object
1944 - Number of Visible People in a Queue.<p>Hard</p> <p>There are <code>n</code> people standing in a queue, and they numbered from <code>0</code> to <code>n - 1</code> in <strong>left to right</strong> order. You are given an array <code>heights</code> of <strong>distinct</strong> integers where <code>heights[i]</code> represents the height of the <code>i<sup>th</sup></code> person.</p> <p>A person can <strong>see</strong> another person to their right in the queue if everybody in between is <strong>shorter</strong> than both of them. More formally, the <code>i<sup>th</sup></code> person can see the <code>j<sup>th</sup></code> person if <code>i < j</code> and <code>min(heights[i], heights[j]) > max(heights[i+1], heights[i+2], ..., heights[j-1])</code>.</p> <p>Return <em>an array</em> <code>answer</code> <em>of length</em> <code>n</code> <em>where</em> <code>answer[i]</code> <em>is the <strong>number of people</strong> the</em> <code>i<sup>th</sup></code> <em>person can <strong>see</strong> to their right in the queue</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/05/29/queue-plane.jpg" alt="" /></p> <p><strong>Input:</strong> heights = [10,6,8,5,11,9]</p> <p><strong>Output:</strong> [3,1,2,1,1,0]</p> <p><strong>Explanation:</strong></p> <p>Person 0 can see person 1, 2, and 4.</p> <p>Person 1 can see person 2.</p> <p>Person 2 can see person 3 and 4.</p> <p>Person 3 can see person 4.</p> <p>Person 4 can see person 5.</p> <p>Person 5 can see no one since nobody is to the right of them.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> heights = [5,1,2,3,10]</p> <p><strong>Output:</strong> [4,1,1,1,0]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == heights.length</code></li> <li><code>1 <= n <= 10<sup>5</sup></code></li> <li><code>1 <= heights[i] <= 10<sup>5</sup></code></li> <li>All the values of <code>heights</code> are <strong>unique</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • canSeePersonsCount

      public int[] canSeePersonsCount(int[] heights)