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();
}
};
-
1:32:34
Glenn Greenwald
7 hours agoThe Future of Gaza With Abubaker Abed; Journalist Sam Husseini On His Physical Expulsion From Blinken’s Briefing & Biden’s Gaza Legacy | System Update #391
80.4K65 -
1:34:48
Roseanne Barr
10 hours ago $16.12 earnedWe are so F*cking Punk Rock! with Drea de Matteo | The Roseanne Barr Podcast #83
65.8K39 -
1:08:20
Man in America
11 hours ago🇨🇳 RedNote: A CCP Trojan Horse Deceiving Americans? w/ Levi Browde
27.1K32 -
3:55:11
I_Came_With_Fire_Podcast
14 hours agoTrump SABOTAGE, LA FIRE CHIEF SUED, and BIDEN’S LAST F-U!
15.1K7 -
2:59:47
Joker Effect
5 hours agoUkraine in a video game? Hardest thing I have done. S.T.A.L.K.E.R.2 Heart of Chornobyl,
56.1K4 -
1:15:22
Flyover Conservatives
1 day agoEczema, Brain Fog, B.O., and Gas… Eating Steak and Butter Creates Ultimate Health Hack - Bella, Steak and Butter Gal | FOC Show
46.2K2 -
51:58
PMG
9 hours ago $2.01 earned"Can the Government Learn from Elon Musk’s 70% Labor Cut? A Deep Dive into Inefficient Agencies"
31.7K -
6:39:15
Amish Zaku
8 hours agoRumble Spartans #10 - New Year New Maps
28.9K2 -
1:04:58
In The Litter Box w/ Jewels & Catturd
1 day agoNo Tax On Tips! | In the Litter Box w/ Jewels & Catturd – Ep. 722 – 1/17/2025
149K32 -
5:35:39
Dr Disrespect
15 hours ago🔴LIVE - DR DISRESPECT - WARZONE - CRAZY CHALLENGES
170K33