CheckbookRegister
Rookie SRM 7 · 2021-11-25 · by erinn
Problem Statement
You need to update the balance in your checkbook. You know your starting balance, the total amount spent using your debit card, and the total value of checks that have been written. Return your ending balance.
Notes
- Just like in real life, it's possible for you to end up negative.
Constraints
- startingBalance will be between 1 and 10000, inclusive.
- debits will be between 0 and 10000, inclusive.
- checks will be between 0 and 10000, inclusive.
1000 100 200 Returns: 700
You had 1000, withdrew 100 at an ATM, and wrote a check for 200. That leaves you with 700. (1000 - 100 - 200 = 700)
500 210 290 Returns: 0
You're all out of money.
800 0 0 Returns: 800
You haven't spent any of your money in this case.
500 300 450 Returns: -250
Oops... you overdrew your account.
9876 1234 5678 Returns: 2964
Submissions are judged against all 19 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CheckbookRegister with a public method int updateBalance(int startingBalance, int debits, int checks) · 19 test cases · 2 s / 256 MB per case