01 April 2017

Are Similar?

My solution:
bool areSimilar(int[] A, int[] B) 
{
    if (A.Where((t, i) => t != B[i]).Count() > 2)
        return false;

    return A.Distinct().OrderBy(x => x).SequenceEqual(B.Distinct().OrderBy(x => x).ToArray());
}

Previous Next