Skip to the code
cf.
+10 XP

#264 Panels With a Clear View

easy

A dashboard lays out panels in a row, and heights[i] is the height of panel i. A sidebar is on the far right. A panel has a clear view of the sidebar if every panel to its right is strictly shorter.

Write clearView(heights) that returns the indexes of the panels with a clear view, in increasing order. The last panel always has one.

Example 1

Input: heights = [4,2,3,1]
Output: [0,2,3]

Panel 1 (height 2) is blocked by panel 2 (height 3).

Example 2

Input: heights = [4,3,2,1]
Output: [0,1,2,3]

Heights only go down, so every panel can see.

Constraints

  • 1 <= heights.length <= 10^5
  • 1 <= heights[i] <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).