Skip to content

Commit bf2d6ce

Browse files
committed
Mar 31
1 parent d883a4a commit bf2d6ce

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from itertools import pairwise
2+
3+
4+
class Solution:
5+
def putMarbles(self, weights: list[int], k: int) -> int:
6+
pair_sum = [w1 + w2 for w1, w2 in pairwise(weights)]
7+
pair_sum.sort()
8+
diff = 0
9+
for i in range(k - 1):
10+
diff += pair_sum[len(weights) - 2 - i] - pair_sum[i]
11+
return diff
12+
13+
14+
def main():
15+
weights = [1, 3, 5, 1]
16+
k = 2
17+
assert Solution().putMarbles(weights, k) == 4
18+
19+
weights = [1, 3]
20+
k = 2
21+
assert Solution().putMarbles(weights, k) == 0
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
| March 28 | [2503. Maximum Number of Points From Grid Queries](https://leetcode.com/problems/maximum-number-of-points-from-grid-queries/) | Hard | Unsolved |
3535
| March 29 | [2818. Apply Operations to Maximize Score](https://leetcode.com/problems/apply-operations-to-maximize-score/) | Hard | Unsolved |
3636
| March 30 | [763. Partition Labels](https://leetcode.com/problems/partition-labels/) | Medium | Solved |
37-
| March 31 | []() | | |
37+
| March 31 | [2551. Put Marbles in Bags](https://leetcode.com/problems/put-marbles-in-bags/) | Hard | Solved |
3838

3939

4040
## Summary
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 6 | 6 | 0 |
4444
| Medium | 21 | 10 | 11 |
45-
| Hard | 3 | 0 | 3 |
45+
| Hard | 4 | 1 | 3 |

0 commit comments

Comments
 (0)