1333. Maximum AND Value of a Pair in Array

MediumBit ManipulationBit ManipulationGreedyAND

Given an array of at least two non-negative integers, return the maximum bitwise AND obtainable from any pair of distinct positions.

Input: A JSON object {"nums": [<non-negative integers>]}.

Output: Return the maximum AND over all pairs (i < j).

Examples

Example 1
Input: {"nums":[4,8,12,16]}
Output: 8
Explanation: 8 & 12 = 8 is the largest pair AND.
Example 2
Input: {"nums":[1,2]}
Output: 0
Explanation: 1 & 2 = 0.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →