Showing posts with label List Forest Edge. Show all posts
Showing posts with label List Forest Edge. Show all posts

12 May 2017

Make Array Consecutive 2

My solution:
int makeArrayConsecutive2(int[] statues) 
{
    return statues.Max() - statues.Min() + 1 - statues.Length;
}

Previous

Replace Middle

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

Previous Next

Is Smooth?

My solution:
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]);
}

Previous Next

Remove Array Part

My solution:
int[] removeArrayPart(int[] inputArray, int l, int r) 
{
    return inputArray.Select(i => i).Where((i, i1) => i1 < l || i1 > r).ToArray();
}

Previous Next

Concatenate Arrays

My solution:
int[] concatenateArrays(int[] a, int[] b) 
{
    return a.Concat(b).ToArray();
}

Previous Next

First Reverse Try

My solution:
int[] firstReverseTry(int[] arr) 
{
    return arr.Select((i, i1) => i1 == 0 || i1 == arr.Length - 1 ? i1 == 0 ? arr.Last() : arr.First() : i).ToArray();
}

Previous Next

Array Replace

My solution:
int[] arrayReplace(int[] inputArray, int elemToReplace, int substitutionElem) 
{
    return inputArray.Select(i => i == elemToReplace ? substitutionElem : i).ToArray();
}

Previous Next

Create Array

My solution:
int[] createArray(int size) 
{
    return Enumerable.Repeat(1, size).ToArray();
}

Previous Next