Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 46c5935

Browse files
committed
Solve 2279. Maximum Bags With Full Capacity of Rocks
1 parent f82c9fc commit 46c5935

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
3+
fun maximumBags(capacity: IntArray, rocks: IntArray, additionalRocks: Int): Int {
4+
var fullBags = 0
5+
var remainingRocks = additionalRocks
6+
val emptySpaces = capacity.mapIndexed { i, capacity -> capacity - rocks[i] }.sorted()
7+
8+
var emptySpaceIndex = 0
9+
while (remainingRocks > 0 && emptySpaceIndex < emptySpaces.size) {
10+
if (remainingRocks < emptySpaces[emptySpaceIndex]) {
11+
break
12+
}
13+
14+
remainingRocks -= emptySpaces[emptySpaceIndex]
15+
emptySpaceIndex++
16+
fullBags++
17+
}
18+
19+
return fullBags
20+
}
21+
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /