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

207
Visualizações
maximum value that can be filled

I am trying to learn and practice data structure and I am practicing dynamic programming, and I am stuck over one problem. I don't know if it is my logical fallacy or anything.

my problem statement is:

for a given N number of the bucket with L[i] pints of liquids in it and there is a barrel of capacity C pints, we have to find the most liquid that the barrel can be put from that bucket if the barrel should not overflow.

This is my code:

let V1 = [2, 3, 4, 2];
let barrel = 100;

const cache = [];
for(let i=0; i<=barrel; i++){
    cache[i] = [];
    for(let j=0; j<=V1.length; j++){
        cache[i][j] = 0;
    }
}

function findMaxDP(V1) {
    let i, j;
    let V = [0, ...V1];
    for(i=0; i<=barrel; i++){
        for(j=0; j<V.length; j++){
            if(i==0){
                cache[0][j] = 0;
            }
            if(j==0){
                cache[i][0] = 0;
            }
            else{
                if(i == V[j]){
                cache[i][j] = V[j];
            }
                if((i-cache[i][j-1]) <= V[j]){
                cache[i][j] = cache[i][j-1] + V[j];
            }
                if((i-cache[i][j-1]) != V[j]){
                cache[i][j] = cache[i][j-1];
            }   
            }
        }
    }
    return cache[barrel-1][j-1]
}

console.log(findMaxDP(V1));

I am getting zero, any kind of help would be appreciated.

Thank you

about 4 years ago · Juan Pablo Isaza
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