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()); }