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
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()); }
string[] addBorder(string[] picture) { return new[] { new string('*', picture.Max(x => x.Length) + 2) }.Concat(picture.Select(x => "*" + x + "*")).Concat(new[] { new string('*', picture.Max(x => x.Length) + 2) }).ToArray(); }
int[] alternatingSums(int[] a) { return new[] { a.Where((b, c) => c % 2 == 0).Sum(), a.Where((b, c) => c % 2 == 1).Sum() }; }
string reverseParentheses(string s) { string cs = s; while (cs.Contains("(")) { string r = Regex.Match(cs, "\\([^\\(\\)]+\\)").Value; string r2 = r.Remove(r.Length - 1, 1); r2 = r2.Remove(0, 1); string r3 = string.Concat(r2.Reverse()); cs = cs.Replace(r, r3); } return cs; }
int[] sortByHeight(int[] a) { int b = 0; return a.Select(c => c == -1 ? c : a.Where(d => d != -1).OrderBy(d => d).ToArray()[b++]).ToArray(); }
bool isLucky(int n) { return Equals(n.ToString().Substring(0, n.ToString().Length / 2).Sum(x => int.Parse(x.ToString())), n.ToString().Substring(n.ToString().Length / 2, n.ToString().Length / 2).Sum(x => int.Parse(x.ToString()))); }
int commonCharacterCount(string s1, string s2) { return s1.ToCharArray().Distinct().Sum(c => Math.Min(s1.Count(x => x == c), s2.Count(x => x == c))); }