Help needed

Problem - You have Given some weights and a value W such that you have to put that weights in boxes which can hold upto W weight per box . What is the minimum number of boxes required such that all the weights can be accumulated .

Eg - N = 5 , W = 5 
        w[] = { 1 , 2 , 3 , 4 , 5 } 
        ans = 3 
        { 1 , 4 } { 2 , 3 } { 3 }

I tried two pointer approach which works greedily but it won’t worked
What could be a DP solution then ??

also
Does Greedy solution also works fine in this case ( supposing that I made some mistake while writing solution ) ?

Or any testcase that contradicts greedy solution ?

1 Like

can you provide the question link

1 Like

I don’t have link
Actually it came in some coding test .
and my friend sent me an image of that question .

1 Like