FastPrepMaximum Barbell Weight

Maximum Barbell Weight

Virtu Financial logoVirtu Financial● HardFULLTIMEOA
Learn

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) → int

Examples

Example 1

weights = [7,1,5,6,2]maxCapacity = 7return = 7

There are three optimal ways to reach total weight 7: choose [7], [1,6], or [2,5].

Constraints

  • 1 <= weights.length <= 42
  • 1 <= maxCapacity <= 10^9
  • 1 <= weights[i] <= 10^9

More Virtu Financial problems

See Virtu Financial hiring insights
public int weightCapacity(int[] weights, int maxCapacity) {
    // Write your code here.
}
weights[7,1,5,6,2]
maxCapacity7
expected7
Checking account…