We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ee781a8 commit 50e089aCopy full SHA for 50e089a
1710-maximum-units-on-a-truck.js
@@ -0,0 +1,16 @@
1
+/**
2
+ * @param {number[][]} boxTypes
3
+ * @param {number} truckSize
4
+ * @return {number}
5
+ */
6
+const maximumUnits = function (boxTypes, truckSize) {
7
+ boxTypes.sort((a, b) => b[1] - a[1])
8
+ let res = 0
9
+
10
+ for (let i = 0; i < boxTypes.length && truckSize > 0; ++i) {
11
+ let used = Math.min(boxTypes[i][0], truckSize)
12
+ truckSize -= used
13
+ res += used * boxTypes[i][1]
14
+ }
15
+ return res
16
+}
0 commit comments