Largest Combination With Bitwise AND Greater Than Zero
Problem Statement
The AND of a group of numbers is the bitwise AND of all of them. For example, 1 & 5 & 3 = 1, and a group with one number has an AND equal to that number.
You are given an array candidates of positive integers. Pick any group of them, using each candidate at most once, and compute the AND of the group. Return the size of the largest group whose AND is greater than 0.
An array candidates of positive integers.
The size of the largest group of candidates whose bitwise AND is greater than 0.
The group [16, 17, 62, 24] has AND 16 & 17 & 62 & 24 = 16 > 0, so its size 4 counts. A group of 5 or more never has AND above 0. The group [62, 12, 24, 14] also works, with AND 8.
8 & 8 = 8 > 0, so the whole array is a valid group of size 2.
- • 1 ≤ candidates.length ≤ 10^5
- • 1 ≤ candidates[i] ≤ 10^7
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Try all 2^N groups, AND each one, keep the biggest with AND > 0
For each bit, count the candidates that have it; the answer is the biggest count
Every group is a subset of the array. For each non-empty group, compute its AND. If the AND is above 0 and the group is bigger than the best so far, keep its size.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Bit Manipulation translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.