bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1046. Last Stone Weight

1046. Last Stone Weight

Leetcode Solutions

Approach: Heap-Based Simulation

  1. Create a Max-Heap from the input array of stones.
  2. While the heap contains more than one stone: a. Remove the two largest stones from the heap (the two max elements). b. If the weights of the stones are not equal, insert the absolute difference back into the heap.
  3. If the heap is empty, return 0.
  4. Otherwise, return the weight of the last remaining stone (the only element left in the heap).
UML Thumbnail

Approach: Array-Based Simulation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...