Trains the technique from
LeetCode 2144Minimum Cost of Buying Candies With DiscountThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A hardware stall prices every clamp on its table separately; price[i] is the price of the i-th clamp. You want to take all of them home, and the stall runs this offer.
Split the clamps into groups however you like, so that every clamp belongs to exactly one group. In a group of exactly three clamps, the cheapest clamp of that group is free and you pay for the other two. In a group of any other size, you pay for every clamp in it.
Return the smallest total you can pay for all of the clamps.
Example 1
Put the clamps priced 8, 6 and 3 in one group: 3 is the cheapest of that group, so it is free and you pay 8 and 6. The clamp priced 1 sits in a group of its own and is paid for, giving 8 + 6 + 1 = 15.
Example 2
Group three of the clamps, taking one of them free and paying for the other two, and leave the fourth in a group of its own, giving 40 + 40 + 40 = 120.
Example 3
One clamp cannot form a group of three, so it is paid for.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def least_paid(price: list[int]) -> int:public int leastPaid(int[] price)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.