Largest Combination With Bitwise AND Greater Than Zero - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
candidates = [16,17,71,62,12,24,14]
›
Output:
4
💡 Note:
The combination [16,17,62,24] has a bitwise AND where bit 4 is set in all numbers, giving AND = 16 > 0. Bit position 4 appears in exactly 4 numbers, which is the maximum across all bit positions.
Example 2 — Small Array
$
Input:
candidates = [8,8]
›
Output:
2
💡 Note:
Both numbers are identical, so we can pick both and their AND = 8 > 0.
Example 3 — No Common Bits
$
Input:
candidates = [1,2,4,8]
›
Output:
1
💡 Note:
Each number has a unique bit set, so maximum combination size with AND > 0 is 1.
Constraints
- 1 ≤ candidates.length ≤ 105
- 1 ≤ candidates[i] ≤ 107
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code