-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.java
32 lines (27 loc) · 940 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//Problem: https://www.hackerrank.com/challenges/linkedin-practice-bitwise-and
//Java 8
/*
Initial Thoughts: We can simple iterate over each element and
all the elements to the right of it and check
if it satisfies our condition.
Optimization: There is a pattern to the highest potential &, so we
can use this to determine the ma in O(1) time
Time Complexity: O(1)
Space Complexity: O(1)
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
for(int t = 0; t < T; t++)
{
int max = 0;
int n = input.nextInt();
int k = input.nextInt();
if (((k-1)|k) <= n) System.out.println(k-1);
else System.out.println(k-2);
}
}
}