AND choice
Practice
2.9 (14 votes)
Algorithms
Bit manipulation
Data structures
Math
Priority queue
Trees
Problem
93% Success 5023 Attempts 30 Points 2.5s Time Limit 256MB Memory 1024 KB Max Code
M is alone and he has an array \(a_1, a_2, ..., a_n\). M wants to choose two integers \(i, j\) such that \(i \neq j, 1 \leq i, j \leq n\) and the value \(a_i \& a_j\)(bitwise AND) is maximum.
What is the maximum value M can get?
Input
First line contains only \(n\), legnth of array.
Second line contains the array elements \(a_1, a_2, ..., a_n\)separated by space.
\(1 \leq n \leq 3 \times 10^5\)
\(1 \leq a_i \leq 10^9\)
Output
The only line of output contains an integer, maximum value value that M can get.
Submissions
Please login to view your submissions
Similar Problems
Points:30
74 votes
Tags:
ApprovedEasyOpenPriority queue
Points:30
155 votes
Tags:
ApprovedEasyHeapsOpenPriority queueTrees
Editorial