30 Day code challenge-python
Day 29 — Bitwise AND
Task
Given set S={1, 2, 3…, N}. Find two integers, A and B (where ), 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.
Function Description
Complete the bitwiseAnd function in the editor.
bitwiseAnd has the following parameter(s):
int N: the maximum integer to consider
int K: the limit of the result, inclusive
Returns
int: the maximum value of A&B within the limit.
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.
Explanation:
Line 1–9: Gets input from the user and creates two lists.
Line 11–19: The maximum bitwise value of each input from the list is calculated and the maximum value is returned.
Line 21: Prints the maximum value.
Bonus Tip: ‘&’ adds two values based on their decimal values.
Finally, 30 days of code comes to an end