Maximum Barbell Weight
Updated
Problem 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 Online Assessment questions
- Count Subarrays With Product Equal to KOA · Seen Nov 2026
- Minimum No-Repeat Segments After One Character RemovalOA · Seen Nov 2026
- Get Message StatusOA · Seen Nov 2026
- Minimum Unique-Character Segments After DeletionOA · Seen Sep 2026
- Run-Length String CompressionOA · Seen Sep 2026
- Maximum Requests in WindowOA · Seen Sep 2026
- Final Pod Counts After LogsOA · Seen Aug 2026
- Minimum Removals to Balance ArrayOA · Seen Aug 2026
- Is This Date a Weekend?OA · Seen Aug 2026
- Minimum Operations to ZeroOA · Seen Jul 2026
Similar questions at other companies
- Maximum Barbell WeightVirtu Financial · OAVirtu Financial interview questions
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Sliding Window MedianAuxoAI · OA
- Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
- Maximum Non-Decreasing Array LengthVisa · OAVisa interview questions
- Pressure-Isolation Shutdown OrderIntuit · OAIntuit interview questions
- Minimum Cost to Make Array EqualWalmart · OAWalmart interview questions
- Maximize Array Beauty After DeletionsPoint72 · OAPoint72 interview questions
- Longest Subarray with Sum at Most KGoogle · OAGoogle interview questions
- Data ReorganizationGoldman Sachs · OAGoldman Sachs interview questions