Three for the price of two
- O(1) · Trivial
- Free
- Python
- JavaScript
- operations
- division
Problem
Buy three, pay for two: out of every three items you drop in the cart, one is free. Take how many items you are buying and the price of one, and return what you pay.
With 7 items at 30 you pay for 5 of them: 150. With 2 items there is no trio yet, so you pay for both. With an empty cart you pay 0.
Examples
7, 30 → 150
3, 20 → 40
Not a trio yet
2, 25 → 50
6, 15 → 60
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def pay(items, price):
passJavaScript
function pay(items, price) {
}Solve this challenge
It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.