Lifting Weights
Updated
Problem statement
Select a subset of the plates in weights whose total weight does not exceed maxCapacity. Each array occurrence is one plate and may be selected at most once, even when several plates have the same weight.
Return the maximum possible total weight. The empty subset is allowed and has weight 0. Maximize weight rather than the number of plates; no left/right symmetry requirement is imposed. For this exercise, assume the input array must remain unchanged.
Function
weightCapacity(weights: int[], maxCapacity: int) → intExamples
Example 1
weights = [1,3,5]maxCapacity = 7return = 6The subset 1+5 has weight 6, the largest total not exceeding 7.
Example 2
weights = [8,9]maxCapacity = 7return = 0Neither plate fits, so choose the empty subset.
Example 3
weights = [4,4,6]maxCapacity = 8return = 8The two distinct 4-weight plates may both be selected.
Constraints
1 <= weights.length <= 42.1 <= weights[i], maxCapacity <= 1000000000.- The returned selected total is at most
maxCapacityand fits an int; intermediate arithmetic uses wider values where needed.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
- Cat Route Budget Planning (Game Adaptation)OA · Seen Aug 2025
Similar questions at other companies
- Split Array to Minimize the Largest SumInfosys · OAInfosys interview questions
- Sliding Window MedianAuxoAI · OA
- Maximum Barbell WeightVirtu Financial · OAVirtu Financial interview questions
- Maximum Non-Decreasing Array LengthVisa · OAVisa 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
- Maximum Barbell WeightSalesforce · OASalesforce interview questions
- Data ReorganizationGoldman Sachs · OAGoldman Sachs interview questions
- Find Least Possible VulnerabilityAmazon · OA