Skip to the content

The candy left in the bag

Problem

You're sharing a bag of candy with your friends: everyone gets the same number of whole pieces, and the ones that aren't enough to give each of them one more stay in the bag.

Write a function that takes how many pieces there are and how many friends there are, and returns how many stay in the bag. With 10 pieces and 4 friends, 2 are left. If there's less candy than friends, nobody gets any and all of it stays.

Examples

  • 10, 4 → 2

  • Shares out evenly

    12, 4 → 0

  • Less candy than friends

    3, 5 → 3

Besides these, the challenge has hidden tests that are revealed when you submit your solution.

You start with this

Python

def leftovers(candy, friends):
    pass

JavaScript

function leftovers(candy, friends) {
}
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.

More O(1) challenges

See all challenges →