Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda