Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
How can i solve transfer from Bank A to Bank B

enter image description here enter image description here

You are given a list of N transfers (numbered from 0 to N-1) between two banks: bank A and bank B. The K-th transfer is described by two values: . R[K] (either "A" or "B") representing the recipient (the bank the transfer is sent to); V[K] 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 (i.e. their account balance may not drop below 0). What minimum initial account balance in each bank is necessary in order to complete the transfers? Write a function: a vector int> solution(string &R, vector int> &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 a vector of integers. Examples: Examples: 1. Given R = "BAABA' and V = [2,4,1,1,2], the function should return [2,4). The bank accounts' balances after each transfer are shown in the following table: ΤΑΙ Β initial balance 2 / 4 transfer 2 from A to B 10 | 6 transfer 4 from B to A | 4 | 2 transfer 1 from B to A | 5 | 1 transfer 1 from A to B | 4 | 2 transfer 2 from B to A 6 10 2. Given R = "ABAB" and V = [10, 5, 10, 15), the function should return [0, 15) 3. Given R = "B" and V = [100], the function should return (100,0). Write an efficient algorithm for the following assumptions: string R and array V are both of length N; • Nis an integer within the range [1..100,000); • each element of array V is an integer within the range [1..10,000); • strina R consists only of the characters "A" and/or "B". enges saved

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

def initial_amount(R, V):
    min_A, min_B, balance = 0, 0, 0
    for receiver, amount in zip(R, V):
        if receiver == 'A':
            balance += amount
            min_B = min(-balance, min_B)
        else:
            balance -= amount
            min_A = min(balance, min_A)
    return [-min_A, -min_B]

initial_amount('BAABA', [2,4,1,1,2])
 [2, 4]

initial_amount('ABAB', [10,5,10,15])
[0, 15]

initial_amount('B', [100])
[100, 0]
about 4 years ago · Juan Pablo Isaza Relatório

0

Javascript solution

function solution(R, V) {
  let min_A = 0;
  let min_B = 0;
  let balance = 0;
  let arr = [];
  let final = [];

  R = R.split('');
  for (var i = 0; i < R.length; i++) {
    arr.push({
      receiver: R[i],
      amount: V[i],
    });
  }
  arr.map((k) => {
    if (k.receiver == 'A') {
      balance += k.amount;
      min_B = Math.min(-balance, min_B)
    } else {
      balance -= k.amount;
      min_A = Math.min(balance, min_A)
    }
  });
  final.push(Math.abs(min_A), Math.abs(min_B));
  console.log(final);
  console.log(min_A, min_B);
}
solution('B', [100]);

about 4 years ago · Juan Pablo Isaza Relatório

0

JavaScript solution:

function solution(R, V) {
  let initialBalances = [0, 0];
  let minA = 0;
  let minB = 0;

  for (let i = 0; i < R.length; i++) {

    if (R[i] === 'A') {
      initialBalances[1] -= V[i]; 
      initialBalances[0] += V[i]; 
      minB = Math.min(minB, initialBalances[1]);
    } else { 
      initialBalances[0] -= V[i]; 
      initialBalances[1] += V[i]; 
      minA = Math.min(minA, initialBalances[0]);
    }
  }

  return [Math.abs(minA), Math.abs(minB)];
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda