Skip to the code
cf.
+25 XP

#103 Largest Area Between Two Dividers

medium

A dashboard layout has vertical dividers placed one unit apart. heights[i] is the height of divider i. You can stretch a panel between any two dividers i < j: its width is j - i and its height is the shorter of the two dividers.

Write largestPanel(heights) that returns the largest panel area, (j - i) * Math.min(heights[i], heights[j]), over all pairs. Return 0 if there are fewer than two dividers.

Example 1

Input: heights = [2,7,4,1,6,3,5]
Output: 25

Dividers 1 and 6 have heights 7 and 5, so the area is 5 * 5 = 25.

Example 2

Input: heights = [3,3]
Output: 3

Width 1, height 3.

Constraints

  • 0 <= heights.length <= 100000
  • 0 <= heights[i] <= 10^4
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).