forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101_19.py
More file actions
28 lines (25 loc) · 791 Bytes
/
101_19.py
File metadata and controls
28 lines (25 loc) · 791 Bytes
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
# Bitwise AND operation - Timeout error
# SOLUTION from Jakus hackerrank passes all the testcase, based on the strucuture of AND logic
#!/bin/python
import sys
t = int(raw_input().strip())
for a0 in xrange(t):
n,k = raw_input().strip().split(' ')
n,k = [int(n),int(k)]
# Logic based on Jakus explanation in hackerank
# if k is odd, k-1 is even, k-1 & k == k-1 and k-1 | k == k
# if k is even, k-1 is odd, k-1 can be reached if k-1 | k <= n
print k-1 if (k-1 | k) <= n else k-2
"""
maxi = 0
initk = k
for i in range(1,n):
k = initk+1
while k <= n:
value = i&k
if value > maxi and value < initk:
maxi = value
break
k += 1
print maxi
"""