Skip to content

Commit e345cb4

Browse files
committed
Mar 14
1 parent d3a651a commit e345cb4

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution:
2+
def maximumCandies(self, candies: list[int], k: int) -> int:
3+
left, right = 1, max(candies)
4+
max_candies = 0
5+
while left <= right:
6+
mid = left + (right - left) // 2
7+
n_piles = sum(candy // mid for candy in candies)
8+
if n_piles >= k:
9+
max_candies = max(max_candies, mid)
10+
left = mid + 1
11+
else:
12+
right = mid - 1
13+
return max_candies
14+
15+
16+
def main():
17+
candies = [5, 8, 6]
18+
k = 3
19+
assert Solution().maximumCandies(candies, k) == 5
20+
21+
candies = [2, 5]
22+
k = 11
23+
assert Solution().maximumCandies(candies, k) == 0
24+
25+
26+
if __name__ == '__main__':
27+
main()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
| March 10 | [3306. Count of Substrings Containing Every Vowel and K Consonants II](https://leetcode.com/problems/count-of-substrings-containing-every-vowel-and-k-consonants-ii/) | Medium | Unsolved |
1717
| March 11 | [1358. Number of Substrings Containing All Three Characters](https://leetcode.com/problems/number-of-substrings-containing-all-three-characters/) | Medium | Solved |
1818
| March 12 | [2529. Maximum Count of Positive Integer and Negative Integer](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/) | Easy | Solved |
19-
| March 13 | [](https://leetcode.com/problems/zero-array-transformation-ii/) | Medium | Unsolved |
20-
| March 14 | []() | | |
19+
| March 13 | [https://leetcode.com/problems/zero-array-transformation-ii/](https://leetcode.com/problems/zero-array-transformation-ii/) | Medium | Unsolved |
20+
| March 14 | [2226. Maximum Candies Allocated to K Children](https://leetcode.com/problems/maximum-candies-allocated-to-k-children/) | Medium | Solved |
2121
| March 15 | []() | | |
2222
| March 16 | []() | | |
2323
| March 17 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 5 | 5 | 0 |
44-
| Medium | 8 | 4 | 4 |
44+
| Medium | 9 | 5 | 4 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)