int makeArrayConsecutive2(int[] statues) { return statues.Max() - statues.Min() + 1 - statues.Length; }
Previous
int makeArrayConsecutive2(int[] statues) { return statues.Max() - statues.Min() + 1 - statues.Length; }
int[] replaceMiddle(int[] arr) { return arr.Length % 2 == 1 ? arr : arr.Select((i, i1) => i1 != arr.Length / 2 - 1 ? i : arr[arr.Length / 2 - 1] + arr[arr.Length / 2]) .Where((i, i1) => i1 != arr.Length / 2) .ToArray(); }
bool isSmooth(int[] arr) { return arr.Length % 2 == 0 ? arr.First().Equals(arr.Last()) && arr.First().Equals(arr[arr.Length / 2 - 1] + arr[arr.Length / 2]) : arr.First().Equals(arr.Last()) && arr.First().Equals(arr[arr.Length / 2]); }
int[] removeArrayPart(int[] inputArray, int l, int r) { return inputArray.Select(i => i).Where((i, i1) => i1 < l || i1 > r).ToArray(); }
int[] concatenateArrays(int[] a, int[] b) { return a.Concat(b).ToArray(); }
int[] firstReverseTry(int[] arr) { return arr.Select((i, i1) => i1 == 0 || i1 == arr.Length - 1 ? i1 == 0 ? arr.Last() : arr.First() : i).ToArray(); }
int[] arrayReplace(int[] inputArray, int elemToReplace, int substitutionElem) { return inputArray.Select(i => i == elemToReplace ? substitutionElem : i).ToArray(); }
int[] createArray(int size) { return Enumerable.Repeat(1, size).ToArray(); }
int candles(int candlesNumber, int makeNew) { var sum = candlesNumber; while (candlesNumber >= makeNew) { sum += candlesNumber / makeNew; candlesNumber = candlesNumber / makeNew + (candlesNumber - candlesNumber / makeNew * makeNew); } return sum; }
int rounders(int value) { if (value < 10) return value; var ic = value.ToString().Reverse().ToList(); var s = "0"; for (var i = 1; i < ic.Count; i++) { if (ic[i - 1] > '4') { if (ic[i] == '9') ic.Add('1'); ic[i] = ic[i] != '9' ? (char) (ic[i] + 1) : '0'; } if (i != ic.Count - 1) s += "0"; else if (ic[i] != '9') s += ic[i]; else s += "01"; } return int.Parse(new string(s.Reverse().ToArray())); }
bool increaseNumberRoundness(int n) { return n.ToString().TrimEnd('0').Contains('0'); }
int appleBoxes(int k) { return Enumerable.Range(1, k).Select(i => Convert.ToInt32(Math.Pow(-1, i) * Math.Pow(i, 2))).Sum(); }
int additionWithoutCarrying(int param1, int param2) { return (param1 / 10000 + param2 / 10000) % 10 * 10000 + (param1 / 1000 + param2 / 1000) % 10 * 1000 + (param1 / 100 + param2 / 100) % 10 * 100 + (param1 / 10 + param2 / 10) % 10 * 10 + (param1 + param2) % 10; }
int lineUp(string commands) { var b = true; var count = 0; foreach (var c in commands) if ((c == 'L' || c == 'R') && b) b = false; else if ((c == 'L' || c == 'R') && !b) { b = true; count++; } else if (c == 'A') if (b) count++; return count; }
int countSumOfTwoRepresentations2(int n, int l, int r) { var count = 0; for (var a = l; a <= r; a++) if (a <= n - a && n - a >= l && n - a <= r) count++; return count; }
int leastFactorial(int n) { var i = 1; while (Factorial(i) < n) i++; return Factorial(i); } int Factorial(int p0) { if (p0 > 1) return Factorial(p0 - 1) * p0; return 1; }