Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Largest water container

    Largest water container

    Mediumarraytwo pointersgreedy

    heights[i] is the height of a wall at position i. Pick two walls that, with the ground, form a container holding (distance between them) × (height of the shorter one). Return the maximum water possible.

    Example 1

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

    Walls 8 (position 1) and 7 (position 8): 7 × 7 = 49.

    Example 2

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

    Constraints

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

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

    /**
     * @param {int[]} heights
     * @return {int}
     */
    function maxArea(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.