Skip to content

Latest commit

 

History

History

day-29-bitwise-and

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Day 29: Bitwise AND

https://www.hackerrank.com/challenges/30-bitwise-and

Problem

Welcome to the last day! Today, we're discussing bitwise operations.

Task

Given set S = { 1, 2, 3, ..., N }. Find two integers, A and B (where A < B), from set S such that the value of A&B is the maximum possible and also less than a given integer, K. In this case, & represents the bitwise AND operator.

Input format

The first line contains an integer, T, the number of test cases.
Each of the T subsequent lines defines a test case as 2 space-separated integers, N and K, respectively.

Output Format

For each test case, print the maximum possible value of A&B on a new line.

Sample Input

3
5 2
8 5
2 2

Sample Output

1
4
0

My Solution