Subset of atleast sum k

i did subset of sum K.and now I am trying to modify it to subset of atleast sum k.I am not able to do. please check my code and help me in modification.

hello @samardeep

why r u applying dp here.

simply check sum of all +ve elements .
if sum >=k then pick all poisitive elements as ur answer

else not possible

i want subset fro the array

give me any one example

like minimum no of elements for sum atleast greater than sum k

6 15 2 4 5 6 7 8 ans is 2 ,7+8=15 and also 4+5+6 =15 but minimum no is 2,so we will pick 2

yeah even this is easy.

first consider all +ve elements (assuming their sum >= k) .

then sort them in ascending order and then keep removing smaller elements till sum >= k holds
in the end u will left with minimum length subset with sum >=k

i want length as well as the elements those a making a sum>=k and it would be more easier if you provide me the code

check here->

algo->
sort given array in descending order
and then keep picking larger elements

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.