Member-only story
Last Stone 🗿 Weight ⚖️ | Daily LeetCode Challenge | Day 7 | Coding Interview
3 min readApr 7, 2022
Let’s solve the todays LeetCode challenge and see how we should approach this type of problems. I will discuss the brute force as well as the efficient solution (faster than 100% other submissions 🤓 “according to leetcode”).
If you are preparing for an online coding interview, this might help.
Description
We are given a list of stone weights which are all integers, weights, where weights[i] is the weight of the ith stone.
The rule of the game is as follows:
- At each turn, two stones with highest weights x and y are picked and slammed together.
- If x == y, then both the stones destroy each other.
- And, if x ≥ y, then y is completely destroyed and x is left with a weight of x-y.
- This is repeated as long as…