# Max and | hackerearth solution

Problem

You are given array $�$$�$ each containing $�$ inetegers. You have to create array $�$ of $�$ inetegers where ${�}_{�}={�}_{�}\mathrm{&}{�}_{�}$ (Here, $\mathrm{&}$ denotes the Bitwise AND operation). You can shuffle elements of  $�$$�$  however you want. Find maximum value of ${�}_{1}\mathrm{&}{�}_{2}\mathrm{&}\dots \mathrm{&}{�}_{�}$.

Input format

• The first line contains $�$ denoting the number of test cases. The description of $�$ test cases is as follows:
• For each test case:
• The first line contains an integer $�$ denotes size of array $�$$�$.
• The next line contains $�$ space-separated integers ${�}_{1},{�}_{2},\dots ,{�}_{�}$ - denoting the elements of $�$.
• The next line contains $�$ space-separated integers ${�}_{1},{�}_{2},\dots ,{�}_{�}$ - denoting the elements of $�$.

Output format

For each test case, print maximum value of ${�}_{1}\mathrm{&}{�}_{2}\mathrm{&}\dots \mathrm{&}{�}_{�}$ in a separate line.

Constraints

$1\le �\le {10}^{5}\phantom{\rule{0ex}{0ex}}1\le �\le {10}^{5}\phantom{\rule{0ex}{0ex}}\phantom{\rule{0ex}{0ex}}0\le {�}_{�},{�}_{�}\le {10}^{9}$

The sum of  $�$ over all test cases does not exceed ${10}^{5}$.

Sample Input
1
2
3 2
2 3
Sample Output
2
Time Limit: 1
Memory Limit: 256

Source Limit:

Code(C++):-

#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
void fastscan(int &number)
{
bool negative = false;
register int c;
number = 0;
c = getchar();
if (c == '-')
{
negative = true;
c = getchar();
}
for (; (c > 47 && c < 58); c = getchar())
number = number * 10 + c - 48;
if (negative)
number *= -1;
}
void solve()
{
int n;
fastscan(n);
int arr_a[100005];
int arr_b[100005];
int ans = 0xFFFFFFFF;
for (size_t i = 0; i < n; i++)
{
fastscan(arr_a[i]);
}
for (size_t i = 0; i < n; i++)
{
fastscan(arr_b[i]);
ans &= arr_a[i] & arr_b[i];
}
cout << ans << endl;
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int q;
fastscan(q);
while (q--)
{
solve();
}
return 0;
}

Code(JAVA):-

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.stream.LongStream;
class TestClass {
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
}
public Reader(String file_name) throws IOException {
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
}
public String readLine() throws IOException {
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1) {
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException {
int ret = 0;
while (c <= ' ')
boolean neg = (c == '-');
if (neg)
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException {
long ret = 0;
while (c <= ' ')
boolean neg = (c == '-');
if (neg)
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException {
double ret = 0, div = 1;
while (c <= ' ')
boolean neg = (c == '-');
if (neg)
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
buffer[0] = -1;
}
private byte read() throws IOException {
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
public static void main(String[] args) throws IOException {
LongStream.range(0, testcase).map(a -> {
try {
} catch (IOException e) {
throw new RuntimeException(e);
}
}).map(f -> {
try {
} catch (IOException e) {
throw new RuntimeException(e);
}
}).forEach(System.out::println);
}
long result = Long.MAX_VALUE;
for (int i = 0; i < 2 * limit; i++) {
}
return result;
}
}

### Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-