Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!