using
System;
using
System.Collections.Generic;
class
GFG{
static
int
calculate(List<
int
> section,
int
pos)
{
if
(pos < 0)
return
0;
List<
int
> on_section =
new
List<
int
>(),
off_section =
new
List<
int
>();
foreach
(
int
el
in
section)
{
if
(((el >> pos) & 1) == 0)
off_section.Add(el);
else
on_section.Add(el);
}
if
(off_section.Count == 0)
return
calculate(on_section, pos - 1);
if
(on_section.Count == 0)
return
calculate(off_section, pos - 1);
return
Math.Min(calculate(off_section, pos - 1),
calculate(on_section, pos - 1)) +
(1 << pos);
}
static
int
minXorValue(
int
[]a,
int
n)
{
List<
int
> section =
new
List<
int
>();
for
(
int
i = 0; i < n; i++)
section.Add(a[i]);
return
calculate(section, 30);
}
public
static
void
Main(String[] args)
{
int
N = 4;
int
[]A = { 3, 2, 5, 6 };
Console.Write(minXorValue(A, N));
}
}