5 XP challenge

Withdraw Until Empty

very easy
Build it yourself · 3 min
1 Learn2 Predict3 Solve

Task
Your mission

Starting from balance, subtract amount once per period, clamping the balance to zero after each subtraction. Return the final balance. balance is 0 to 100; amount is 0 to 20; periods is 0 to 20.

Examples

InputReturn
balance = 10, amount = 3, periods = 2

answer: 10 → 7 → 4. The result is 4.

4
balance = 10, amount = 3, periods = 4

answer: 10 → 7 → 4 → 1 → -2 → 0. The result is 0.

0

Your code

Write your answer inside Solution, then use return to send it back.

Try examples runs the public examples. Check my code checks your full answer and saves your completion.