Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Largest rectangle in a histogram

    Largest rectangle in a histogram

    Hardstackmonotonic stackarray

    heights are bars of width 1 placed side by side. Return the area of the largest rectangle that fits inside them.

    Example 1

    Input:  heights = [2,1,5,6,2,3]
    Output: 10

    Bars 5 and 6: height 5 × width 2 = 10.

    Example 2

    Input:  heights = [2,4]
    Output: 4

    Constraints

    • 1 ≤ heights.length ≤ 10⁵
    • 0 ≤ heights[i] ≤ 10⁴

    Submit checks your solution against 10 tests, including hidden ones.

    /**
     * @param {int[]} heights
     * @return {int}
     */
    function largestRectangleArea(heights) {
      
    }
    
    Sign in to run
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.