prices with the prices of all the books a customer wants to take home. Each book is either paid for or taken under the promotion, and every pair bought earns at most one free book. Return the minimum total the customer has to pay for all of them.prices=[4, 8, 3, 7, 2] → 20
Buy 8 and 7 and take 4 for free. Then buy 3 and 2; there is no third item left to get for free. The total is 8 + 7 + 3 + 2 = 20.
prices=[5, 5, 5, 5, 5, 5] → 20
Two groups of three: in each one we pay for two items, so the total is 4 × 5 = 20.
prices=[9] → 9
prices=[4, 8, 3, 7, 2]
20
Run checks the first 3 tests in your browser. Submit checks all 87 tests on the server, hidden ones included.