Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    Practice problems / Last stone weight

    Last stone weight

    Easyheapsimulation

    Each turn take the two heaviest stones x ≤ y and smash them: equal stones both vanish, otherwise one stone of weight y - x remains. Continue until at most one stone is left. Return its weight, or 0.

    Example 1

    Input:  stones = [2,7,4,1,8,1]
    Output: 1

    Example 2

    Input:  stones = [1]
    Output: 1

    Constraints

    • 1 ≤ stones.length ≤ 1000
    • 1 ≤ stones[i] ≤ 1000

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

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