Please give approach for this question

Hey @guptanikhil898
1)Sort the array in increasng order.
2)Now take 1’st customer and serve him ,add serving time to varable tot_time
3)Now for each next customer if its time(value)>=tot_time,then ans++ and add tot_time+=a[i]; else if time<tot_time move to next customer :slight_smile:

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.

this is not correct!!

10
2 8 15 1 10 5 19 19 3 5
for this test case correct answer is 5 and occording to you it will be 3

Sort : 1 2 3 5 5 8 10 15 19 19
Now tot_time=0,ans=0;
1>tot_time ans++ (tot_time=1,ans=1)
2>tot_time ans++ (tot_time=3,ans=2)
3==tot_time ans++ (tot_time=6,ans=3)
5<tot_time skip
5<tot_time skip
10>tot_time ans++ (tot_time=16,ans=4)
15<tot_time skip
19>tot_time ans++ (tot_time=35,ans=5)
19<tot_time skip

So ans =5