Skip to content

Commit

Permalink
Add yesterday's leetcode problem.
Browse files Browse the repository at this point in the history
Count of subsets maximizing bitwise or.
  • Loading branch information
iglesias authored Oct 19, 2024
1 parent 00606e9 commit be7e45d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions leetcode/2044.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <cmath>
#include <unordered_map>
#include <vector>

using std::max;

int
solve(std::vector<int> const& nums, int& curMax, std::unordered_map<int ,int>& freqs,
int const curOr = 0, std::vector<int>::size_type const i = 0)
{
freqs[curOr]++;
curMax = max(curMax, curOr);
if (i == nums.size()) return curMax;
for (vector<int>::size_type j = i; j < nums.size(); j++)
curMax = max(curMax, solve(nums, curMax, freqs, curOr | nums[j], j + 1));
return curMax;
}

int
countMaxOrSubsets(vector<int>& nums)
{
std::unordered_map<int, int> freqs;
int curMax = 0;
return freqs[solve(nums, curMax, freqs)];
}

int main() {}

0 comments on commit be7e45d

Please sign in to comment.