Minimum Initial Balances for Ordered Bank Transfers
Updated
Problem statement
Two banks, A and B, execute transfers in the listed order. Transfer i sends V[i] from one bank to the receiving bank named by R[i].
Both banks must start with nonnegative balances, and neither balance may become negative after any transfer. Return the minimum necessary starting balances as an integer array in the order [A, B]. A bank named in R receives that transfer; the other bank sends it.
Function
solution(R: String, V: int[]) → int[]Examples
Example 1
R = "BAABA"V = [2,4,1,1,2]return = [2,4]The balances in [A,B] order are [2,4] initially, then [0,6], [4,2], [5,1], [4,2] and [6,0]. A smaller initial balance for either bank would make some transfer impossible.
Example 2
R = "ABAB"V = [10,5,10,15]return = [0,15]Starting from [0,15] keeps both banks nonnegative through all four transfers.
Example 3
R = "B"V = [100]return = [100,0]Bank A must send 100 to B, so A starts with 100 and B can start with zero.
Constraints
1 <= R.length = V.length <= 100000.Rcontains onlyAandB.1 <= V[i] <= 10000.
More Marshall Wace Online Assessment questions
- Count Letters with Ordered Lowercase and Uppercase OccurrencesOA · Seen Oct 2025
- Maximum Trailing Zeros on a Path with at Most One TurnOA · Seen Oct 2025
- Shortest Subarray Covering an Integer RangeOA · Seen Oct 2025
- Maximum Events in a 60-Second WindowOA · Seen Aug 2025
- Successful Logins from Multiple CountriesOA · Seen Aug 2025
- Maximize Remaining Item Types After Clearing Consecutive ShelvesOA · Seen Nov 2024
- Shortest String After Erasing Equal PairsOA · Seen Nov 2024
- Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)OA · Seen Apr 2024
- Generate Unique Company Email AddressesOA · Seen Apr 2024
- Reconstruct a Two-Row Binary MatrixOA · Seen Apr 2024
Similar questions at other companies
- Minimum Positive Starting ValueBooking.com · OA
- Array Interval SumsHeadlands Technologies · OAHeadlands Technologies interview questions
- Minimum AmountBelvedere Trading · OA
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Range Sum QueriesIntuit · OAIntuit interview questions
- Shortest Distance on a Circular Bus RouteAmazon · OA
- Count Sortable SplitsGoogle · OAGoogle interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Threshold AlertsGoldman Sachs · OAGoldman Sachs interview questions