Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alihalabyah/fe8ad611d8055cd642004065ca3d8464 to your computer and use it in GitHub Desktop.
Save alihalabyah/fe8ad611d8055cd642004065ca3d8464 to your computer and use it in GitHub Desktop.
Problem description:
Write a method that takes in 2 parameters:
A string containing either "A" or "B" indicating the recipient of a bank transfer.
An integer array containing the amount for each of those transfers. So for instance, if the String is BA and the array is [1,2], it means A transfers 1 to B, then B transfers 2 to A.
This method should return what the initial balance for each bank account A and B need to be so that they never go into negative balance.
In the example above, it should return [1, 1].
Initial balance [1, 1].
A transfers 1 to B [0, 2].
B transfers 2 to A [2, 0].
Final balance [2, 0].
Important points:
The input String and the input Array will always have the same length.
The input String will only contain "A" and/or "B". I can't remember if the numbers on the array had to be positive, though I have not tested for negative numbers, so that might be a reason for the failure.
Other test scenarios: "BAABA" - [2,4,1,1,2] - answer should be [2,4].
Initial Balance [2, 4].
A transfers 2 to B [0, 6].
B transfers 4 to A [4, 2].
B transfers 1 to A [5, 1].
A transfers 1 to B [4, 2].
B transfers 2 to A [6, 0].
"ABAB" - [10, 5, 10, 15] answer should be [0, 15].
"B" - [100] - answer should be [100,0].
"AB" - [3, 3] - answer should be [0,3].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment