import
java.util.*;
class
GFG{
static
int
RecursiveFunction(ArrayList<Integer> ref,
int
bit)
{
if
(ref.size() ==
0
|| bit <
0
)
return
0
;
ArrayList<Integer> curr_on =
new
ArrayList<>();
ArrayList<Integer> curr_off =
new
ArrayList<>();
for
(
int
i =
0
; i < ref.size(); i++)
{
if
(((ref.get(i) >> bit) &
1
) ==
0
)
curr_off.add(ref.get(i));
else
curr_on.add(ref.get(i));
}
if
(curr_off.size() ==
0
)
return
RecursiveFunction(curr_on, bit -
1
);
if
(curr_on.size() ==
0
)
return
RecursiveFunction(curr_off, bit -
1
);
return
Math.min(RecursiveFunction(curr_off,
bit -
1
),
RecursiveFunction(curr_on,
bit -
1
)) +
(
1
<< bit);
}
static
void
PrintMinimum(
int
a[],
int
n)
{
ArrayList<Integer> v =
new
ArrayList<>();
for
(
int
i =
0
; i < n; i++)
v.add(a[i]);
System.out.println(RecursiveFunction(v,
30
));
}
public
static
void
main(String[] args)
{
int
arr[] = {
3
,
2
,
1
};
int
size = arr.length;
PrintMinimum(arr, size);
}
}