Premium Only Content

2275. Largest Combination With Bitwise AND Greater Than Zero
The bitwise AND of an array nums is the bitwise AND of all integers in nums.
For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1.
Also, for nums = [7], the bitwise AND is 7.
You are given an array of positive integers candidates. Compute the bitwise AND for all possible combinations of elements in the candidates array.
Return the size of the largest combination of candidates with a bitwise AND greater than 0.
Example 1:
Input: candidates = [16,17,71,62,12,24,14]
Output: 4
Explanation: The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0.
The size of the combination is 4.
It can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.
Note that more than one combination may have the largest size.
For example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.
Example 2:
Input: candidates = [8,8]
Output: 2
Explanation: The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0.
The size of the combination is 2, so we return 2.
Constraints:
1 <= candidates.length <= 105
1 <= candidates[i] <= 107
class Solution {
public:
int largestCombination(vector<int>& candidates) {
int limit = 24;
int ans=0;
for(int i=0; i<limit; i++){
int count=0;
for(int c : candidates){
if(c>>i & 1){
count++;
ans = max(ans,count);
}
}
}
return ans;
}
};
class Solution {
public:
int largestCombination(vector<int>& candidates) {
int limit = 24;
vector<int> ans;
for(int i=23; i>=0; i--){
int count=0;
vector<int> temp;
for(int c : candidates){
if(c>>i & 1){
temp.push_back(c);
}
}
if(ans.size() < temp.size()){
ans = temp;
}
}
for(int a : ans)
cout<<a<<" ";
return ans.size();
}
};
-
4:40
GritsGG
12 hours agoTwo Easter Eggs on Call of Duty Warzone!
7.42K1 -
2:08:19
Side Scrollers Podcast
19 hours agoNetflix Execs to TESTIFY Over LGBTQ Agenda + IGN DESTROYS Xbox Game Pass + More | Side Scrollers
56.1K14 -
5:08:55
Dr Disrespect
17 hours ago🔴LIVE - DR DISRESPECT - BABY STEPS - THE VERY VERY LAST CHAPTER
124K17 -
10:28
BlabberingCollector
13 hours agoAsk Blabs, Episode 5 | Answering Your Wizarding World Related Questions
7.93K1 -
18:09
Forrest Galante
5 days agoI Survived 24 Hours In The World's Deadliest Jungle
187K30 -
LIVE
Lofi Girl
2 years agoSynthwave Radio 🌌 - beats to chill/game to
318 watching -
2:15:09
Badlands Media
17 hours agoOnlyLands Ep. 27: Power Hour Hangover, Trump’s Wartime Shift, and Portland in Flames
113K26 -
22:21
DeVory Darkins
7 hours ago $17.63 earnedRioters attack Portland ICE Facility as Democrats make shocking admission
22.8K87 -
2:06:06
TimcastIRL
10 hours agoTrump DOJ Announces INTERVENTION In Portland Over Nick Sortor Arrest | Timcast IRL
238K388 -
6:53:58
SpartakusLIVE
11 hours ago#1 All-American HERO with LUSCIOUS hair and AVERAGE forehead brings Friday Night HYPE
68.9K7