Problem Statement
When you write a check to purchase something, you make a note of it in a checkbook. That check will eventually make its way to the intended destination, where it will be used to take money out of your bank account. There can be long periods of time between the moment you write a check, and the moment the money is taken from your bank account. When someone finally takes the money from your bank account, the check is said to be reconciled.
In this problem, you have already written some checks. The amounts of these checks will be given in a int[] checks, where each element represents a check amount. In addition, you will be given a int yourBalance that represents how much money will be in your account once all of the checks have been reconciled. Finally, you will be given a int statementBalance that represents how much money is actually in your bank account right at this moment. You will determine which checks have been reconciled. Your method should return a int[] containing the checks that have been reconciled in the order they occur in checks.
The checks that have not been reconciled must add up to statementBalance minus yourBalance. If no such combination of the elements of checks adds up to this difference, return {-1} ( a int[] with one element, -1) signifying a mistake at the bank. If yourBalance is greater than statementBalance, this also must mean a banking mistake, so return {-1} ( a int[] with one element, -1). To make things easier, we will insure that there will be at most 1 combination of checks that sums to the difference between statementBalance and yourBalance (see constraints).
In this problem, you have already written some checks. The amounts of these checks will be given in a int[] checks, where each element represents a check amount. In addition, you will be given a int yourBalance that represents how much money will be in your account once all of the checks have been reconciled. Finally, you will be given a int statementBalance that represents how much money is actually in your bank account right at this moment. You will determine which checks have been reconciled. Your method should return a int[] containing the checks that have been reconciled in the order they occur in checks.
The checks that have not been reconciled must add up to statementBalance minus yourBalance. If no such combination of the elements of checks adds up to this difference, return {-1} ( a int[] with one element, -1) signifying a mistake at the bank. If yourBalance is greater than statementBalance, this also must mean a banking mistake, so return {-1} ( a int[] with one element, -1). To make things easier, we will insure that there will be at most 1 combination of checks that sums to the difference between statementBalance and yourBalance (see constraints).
Definition
- Class:
- Checkbook
- Method:
- reconcile
- Parameters:
- int[], int, int
- Returns:
- int[]
- Method signature:
- int[] reconcile(int[] checks, int yourBalance, int statementBalance)
- (be sure your method is public)
Notes
- Java Users: an empty int[] is NOT the same as null.
Constraints
- checks will contain between 1 and 10 elements, inclusive.
- each element of checks will be between 1 and 10,000,000, inclusive.
- yourBalance will be between 1 and 100,000,000, inclusive.
- statementBalance will be between 1 and 100,000,000, inclusive.
- If there is a way to reconcile the checkbook, there will be only one way to reconcile the checkbook.
Examples
{800,400}900
1300
Returns: { 800 }The check with amount 400 has not been reconciled. Thus the check for 800 has.{800}900
1300
Returns: { -1 }There is no set of checks that makes up for the difference, so we know there must be a problem.{4567,3245,3654,6498,2415}1790
1790
Returns: { 4567, 3245, 3654, 6498, 2415 }yourBalance equals statementBalance{20,10,40,50,80}5000
5200
Returns: { }None of the checks have been reconciled since their amounts sum up to exactly 200.{23482,52423,29434,25234,212343,235234,958343}4523023
2934243
Returns: { -1 }statmentBalance is less than yourBalance{8427,2591,3095,9853,7842,9034,1423,8543,9212,4346}98918
134252
Returns: { 2591, 3095, 9034, 1423, 8543, 4346 }