1364. Largest Combination with Bitwise AND Greater Zero

MediumBit ManipulationBit ManipulationCountingAND

A combination of numbers has a bitwise AND greater than zero exactly when all of them share at least one common set bit. Given an array of positive integers, return the size of the largest such combination.

Input: A JSON object {"candidates": [<positive integers>]}.

Output: Return the maximum number of elements sharing a common set bit.

Examples

Example 1
Input: {"candidates":[16,17,71,62,12,24,14]}
Output: 4
Explanation: The most shared bit appears in four numbers -> 4.
Example 2
Input: {"candidates":[8,8]}
Output: 2
Explanation: Both share the same bit -> 2.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →