Company: JPMC_21july
Difficulty: medium
Maximum Barbell Weight Problem Description An athlete is lifting weights. The barbell has a maximum capacity of maxCapacity . Each barbell plate has a specific weight given by weights[i] . Determine the maximum total weight of plates that can be added to the barbell without exceeding maxCapacity . You need to complete the weightCapacity function. The function takes the following parameters: weights : An array of integers, where each element weights[i] is the weight of a plate. maxCapacity : An integer representing the capacity of the barbell. The function should return an integer: the maximum total weight that can be added. Examples Example 1: Input: weights = [7, 1, 5, 6, 2], maxCapacity = 7 Output: 7 Explanation: The maximum weight that can be added without exceeding 7 is 7. This can be achieved by taking the plate with weight 7, or plates with weights 1 and 6, or plates with weights 2 and 5. Example 2: Input: weights = [1, 3, 5], maxCapacity = 7 Output: 6 Explanation: All the possib