Dsa
Bit Manipulation
Medium
Elite AND-Subset
Given an array of N integers and an integer K, you must choose exactly K elements from the array such that their bitwise AND is maximized. Return the maximum possible AND value.
Input Format:
Two integers N and K.
N integers representing the array.
Output Format:
A single integer.
Example:
Input:
4 2
7 12 15 6
Output:
12
(Explanation: Possible pairs: (7,12)->4, (7,15)->7, (7,6)->6, (12,15)->12, (12,6)->4, (15,6)->6. Max is 12.)
Key concepts
bit_manipulationgreedy
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now