using System;
using System.Collections.Generic;
using System.Linq;
public static class ArrayUtilities
{
/// <summary>
/// Finds the unique intersection of two collections (values that exist in both).
/// Compatible with all Mono runtime versions and standard .NET.
/// </summary>
/// <typeparam name="T">The type of elements in the collections.</typeparam>
/// <param name="first">The first input sequence.</param>
/// <param name="second">The second input sequence.</param>
/// <returns>An array containing unique common elements.</returns>
public static T[] FindArrayIntersection<T>(IEnumerable<T> first, IEnumerable<T> second)
{
// Mono-compatible guard clauses
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
// LINQ Intersect uses HashSet internally for linear O(n + m) time complexity
return first.Intersect(second).ToArray();
}
}
public class Program
{
public static void Main()
{
// Legacy-safe array initialization (compatible across all Mono compiler targets)
int[] arr1 = new int[] { 5, 7, 1, 1, 3, 0, 6, 2 };
int[] arr2 = new int[] { 2, 8, 8, 6, 9, 3, 3, 4, 4 };
// Execute intersection
int[] intersection = ArrayUtilities.FindArrayIntersection(arr1, arr2);
// Print results
Console.WriteLine("Arr1: [{0}]", string.Join(", ", arr1));
Console.WriteLine("Arr2: [{0}]", string.Join(", ", arr2));
Console.WriteLine("Intersection: [{0}]", string.Join(", ", intersection));
// Output: Intersection: [3, 6, 2]
}
}
/*
run:
Arr1: [5, 7, 1, 1, 3, 0, 6, 2]
Arr2: [2, 8, 8, 6, 9, 3, 3, 4, 4]
Intersection: [3, 6, 2]
*/