Here is the problem:
There are n people who want to get to the top of a building which has only one elevator. You know the weight of each person and the maximum allowed weight in the elevator. What is the minimum number of elevator rides?
Constraints1 <= n <= 20
1 <= x <= 10^9
1 <= w_i <= x
for solving this i applied 2 pointer approach but i am getting wrong answer I am not able to figure out the test case when the 2 pointer approach will fail I'm first sorting the weights and then for every heaviest weight i am incrementing answer by 1 and while doing so also clubbing as much lower weights with it till total_sum <= max_allowed_weight
How about you add heaviest person avaiable that can fit into the current ride till no more person can be added.
And repeat until no person available.
I think it is some kind of greedy and much simpler solution.
input:
calc:
output: