Connection Status:
Competition Arena > CheckbookRegister
Rookie SRM 7 · 2021-11-25 · by erinn · Simple Math
Class Name: CheckbookRegister
Return Type: int
Method Name: updateBalance
Arg Types: (int, int, int)
Problem Statement

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.
Examples
0)
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)

1)
500
210
290
Returns: 0

You're all out of money.

2)
800
0
0
Returns: 800

You haven't spent any of your money in this case.

3)
500
300
450
Returns: -250

Oops... you overdrew your account.

4)
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.

Coding Area

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

Submitting as anonymous