public static int CountDifferent(int [] x, int [] y)
if(0 == x.Length + y.Length)
while(kx < x.Length || ky < y.Length)
if(ky == y.Length || (kx < x.Length && x[kx] <= y[ky]))
if(0 == count || smallest > last)
public static void Test(int [] x, int [] y)
Console.WriteLine("Arrays {{{0}}} and {{{1}}} have {2} different values",
string.Join(" ", x), string.Join(" ", y), CountDifferent(x, y));
public static void Main()
int [] empty = new int[0];
Test(empty, new[]{ 1, 2, 3});
Test(new[]{ 1,3}, new[]{ 1, 2, 3});
Test(new[]{ 1,1,1,1}, new[]{ 1});
Test(new[]{ 1,1,1,1}, empty);
Test(new[] { 1,4,7,9,12,45,56} , new[] {1,2,3,5,7,8,45,54,56,67});