Objective
Welcome to the last day! Today, we’re discussing bitwise operations. Check out the Tutorial tab for learning materials and an instructional video!
Task
Given set . 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.
Constraints
Output Format
For each test case, print the maximum possible value of on a new line.
Sample Input
1 | 3 |
Sample Output
1 | 1 |
Explanation
All possible values of and are:
The maximum possible value of A&B that is also < (K = 2) is 1, so we print 1 on a new line.
Solution
1 | function findMax(n, k) { |