Heavy Lifting Elevator

There are n people who want to get to the top of a building. You know the weight of each person. The elevator has a maximum weight capacity x, and you want to find the minimum number of elevator rides needed to transport everyone.

Example 1:

Input: n = 4, x = 10 , w = [4,8,6,1]

Output: 2

Explanation: One optimal grouping:

Ride 1:

8 + 1 = 9

Ride 2:

4 + 6 = 10

Total rides = 2.

Example 2:

Input: n = 3, x = 10 , w = [2,3,5]

Output: 1

Explanation: All people can fit together:

2 + 3 + 5 = 10

So only 1 ride.

Now Your Turn!

Pick the correct output for the given input

Input: n = 4, x = 5 , w = [2,3,4,5]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 ≤ n ≤ 20
  • 1 ≤ x ≤ 109
  • 1 ≤ w[i] ≤ x

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int elevatorRides(int n, int x, vector<int>& weights) {
// Write your code here
return 0;
}
Test Case

Input:

W
X