Problem · Array
Maximum Barbell Weight
Learn this problemProblem statement
An athlete is loading plates onto a barbell with maximum capacity maxCapacity. The weight of each available plate is given by weights[i].
Choose any subset of the plates, using each plate at most once. Return the maximum total plate weight that does not exceed maxCapacity.
Function
weightCapacity(weights: int[], maxCapacity: int) → intExamples
Example 1
weights = [7,1,5,6,2]maxCapacity = 7return = 7There are three optimal ways to reach total weight 7: choose [7], [1, 6], or [2, 5]. Return 7.
Constraints
1 <= weights.length <= 421 <= maxCapacity <= 10^91 <= weights[i] <= 10^9
More Salesforce problems
- Diameter of an Acyclic Undirected GraphONSITE INTERVIEW · Seen Jul 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Jul 2026
- Minimum Operations to ZeroOA · Seen Jul 2026
- Minimize Total Input Cost (for LTMS)OA · Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026