Answered step by step
Verified Expert Solution
Question
1 Approved Answer
code javascript: Given a list of transfers between two banks, determine the minimum initial account balance of each bank required for the given transfers to
code javascript:
Given a list of transfers between two banks, determine the minimum initial account balance of each bank required for the given transfers to be carried out.
Task description
You are given a list of N transfers numbered from to N between two banks: bank A and bank B The Kth transfer is described by two values:
RKeither A or B representing the recipient the bank the transfer is sent to;
VK denoting the value sent via the transfer.
All transfers are completed in the order they appear on the list. The banks do not want to go into debt in other words, their account balance may not drop below What minimum initial account balance in each bank is necessary in order to complete the transfers?
Write a function:
function solutionR V;
that, given a string R and an array of integers V both of length N returns an array of two integers. The integers should represent the minimum initial account balances for banks A and B in the following order: bank A bank B
Result array should be returned as an array of integers.
Examples:
Given R "BAABA" and V the function should return The bank accounts balances after each transfer are shown in the following table:
A B
initial balance
transfer from A to B
transfer from B to A
transfer from B to A
transfer from A to B
transfer from B to A
Given R "ABAB" and V the function should return
Given R B and V the function should return
Write an efficient algorithm for the following assumptions:
string R and array V are both of length N;
N is an integer within the range ;
each element of array V is an integer within the range ;
string R is made only of the characters A andor B
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started