MAX AND
Practice
3.7 (19 votes)
Basic programming
Bit manipulation
Basics of bit manipulation
Problem
58% Success 2638 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given array \(A\)\(B\) each containing \(N\) inetegers. You have to create array \(C\) of \(N\) inetegers where \(C_i = A_i \mathbin{\&} B_i\) (Here, \(\mathbin{\&}\) denotes the Bitwise AND operation). You can shuffle elements of  \(A\)\(B\)  however you want. Find maximum value of \(C_1 \mathbin{\&} C_2 \mathbin{\&} \dots \mathbin{\&} C _N\).

 Input format

  • The first line contains \(T\) denoting the number of test cases. The description of \(T\) test cases is as follows:
  • For each test case:
    • The first line contains an integer \(N\) denotes size of array \(A\)\(B\).
    • The next line contains \(N\) space-separated integers \(A_1, A_2, \dots, A_N\) - denoting the elements of \(A\).
    • The next line contains \(N\) space-separated integers \(B_1, B_2, \dots, B_N\) - denoting the elements of \(B\).

Output format

For each test case, print maximum value of \(C_1 \mathbin{\&} C_2 \mathbin{\&} \dots \mathbin{\&} C _N\) in a separate line.

Constraints

\(1 \leq T \leq 10^5 \\ 1 \leq N \leq 10^5\\ \\0\leq A_i, B_i \leq 10^9\)

The sum of  \(N\) over all test cases does not exceed \(10^5\).

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
12 votes
Tags:
Bit ManipulationBasic ProgrammingBasics of Bit Manipulation
Points:30
256 votes
Tags:
Easy-Medium
Points:20
11 votes
Tags:
Bit ManipulationBasic ProgrammingBasics of Bit ManipulationC++