Skip to content

Commit f97c52e

Browse files
committed
Jul 28
1 parent 0625ae1 commit f97c52e

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class Solution:
2+
def countMaxOrSubsets(self, nums: list[int]) -> int:
3+
m_or = 0
4+
for num in nums:
5+
m_or |= num
6+
result = 0
7+
8+
def dfs(idx: int, curr_or: int) -> None:
9+
if idx == len(nums):
10+
if m_or == curr_or:
11+
nonlocal result
12+
result += 1
13+
return
14+
dfs(idx + 1, curr_or | nums[idx])
15+
dfs(idx + 1, curr_or)
16+
17+
dfs(0, 0)
18+
return result
19+
20+
21+
def main():
22+
nums = [3, 1]
23+
assert Solution().countMaxOrSubsets(nums) == 2
24+
25+
nums = [2, 2, 2]
26+
assert Solution().countMaxOrSubsets(nums) == 7
27+
28+
nums = [3, 2, 1, 5]
29+
assert Solution().countMaxOrSubsets(nums) == 6
30+
31+
32+
if __name__ == '__main__':
33+
main()

2025-07-July-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
| July 25 | [3487. Maximum Unique Subarray Sum After Deletion](https://leetcode.com/problems/maximum-unique-subarray-sum-after-deletion/) | Easy | Solved |
3232
| July 26 | [3480. Maximize Subarrays After Removing One Conflicting Pair](https://leetcode.com/problems/maximize-subarrays-after-removing-one-conflicting-pair/) | Hard | Unsolved |
3333
| July 27 | [2210. Count Hills and Valleys in an Array](https://leetcode.com/problems/count-hills-and-valleys-in-an-array/) | Easy | Solved |
34-
| July 28 | []() | | |
34+
| July 28 | [2044. Count Number of Maximum Bitwise-OR Subsets](https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/) | Medium | Solved |
3535
| July 29 | []() | | |
3636
| July 30 | []() | | |
3737
| July 31 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 7 | 7 | 0 |
44-
| Medium | 10 | 9 | 1 |
44+
| Medium | 11 | 10 | 1 |
4545
| Hard | 9 | 1 | 8 |

0 commit comments

Comments
 (0)