Inclusion Exclusion Principle¶
Table of Contents¶
- 2652. Sum Multiples (Easy)
- 878. Nth Magical Number (Hard)
- 1201. Ugly Number III (Medium)
- 2928. Distribute Candies Among Children I (Easy)
- 2929. Distribute Candies Among Children II (Medium)
- 2930. Number of Strings Which Can Be Rearranged to Contain Substring (Medium)
- 2513. Minimize the Maximum of Two Arrays (Medium)
- 3116. Kth Smallest Amount With Single Denomination Combination (Hard)
- 3130. Find All Possible Stable Binary Arrays II (Hard)
- 3336. Find the Number of Subsequences With Equal GCD (Hard)
- 2927. Distribute Candies Among Children III (Hard) 👑
2652. Sum Multiples¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math
878. Nth Magical Number¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, binary search
1201. Ugly Number III¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, binary search, combinatorics, number theory
2928. Distribute Candies Among Children I¶
-
LeetCode | LeetCode CH (Easy)
-
Tags: math, combinatorics, enumeration
def distributeCandies(n: int, limit: int) -> int:
def c2(n: int) -> int:
return n * (n - 1) // 2 if n > 1 else 0
return (
c2(n + 2)
- 3 * c2(n - limit + 1)
+ 3 * c2(n - 2 * limit)
- c2(n - 3 * limit - 1)
)
if __name__ == "__main__":
assert distributeCandies(5, 2) == 3
assert distributeCandies(3, 3) == 10
2929. Distribute Candies Among Children II¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, combinatorics, enumeration
def distributeCandies(n: int, limit: int) -> int:
def c2(n: int) -> int:
return n * (n - 1) // 2 if n > 1 else 0
return (
c2(n + 2)
- 3 * c2(n - limit + 1)
+ 3 * c2(n - 2 * limit)
- c2(n - 3 * limit - 1)
)
if __name__ == "__main__":
assert distributeCandies(5, 2) == 3
assert distributeCandies(3, 3) == 10
2930. Number of Strings Which Can Be Rearranged to Contain Substring¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, dynamic programming, combinatorics
2513. Minimize the Maximum of Two Arrays¶
-
LeetCode | LeetCode CH (Medium)
-
Tags: math, binary search, number theory
3116. Kth Smallest Amount With Single Denomination Combination¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, binary search, bit manipulation, combinatorics, number theory
3130. Find All Possible Stable Binary Arrays II¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: dynamic programming, prefix sum
3336. Find the Number of Subsequences With Equal GCD¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: array, math, dynamic programming, number theory
2927. Distribute Candies Among Children III¶
-
LeetCode | LeetCode CH (Hard)
-
Tags: math, combinatorics
def distributeCandies(n: int, limit: int) -> int:
def c2(n: int) -> int:
return n * (n - 1) // 2 if n > 1 else 0
return (
c2(n + 2)
- 3 * c2(n - limit + 1)
+ 3 * c2(n - 2 * limit)
- c2(n - 3 * limit - 1)
)
if __name__ == "__main__":
assert distributeCandies(5, 2) == 3
assert distributeCandies(3, 3) == 10