Arrays: Left Rotation

  • + 1 comment

    Here's another slightly different solution. I'm assuming it would be less performant, since it uses List and then converts it to Array, but I'm not sure how much more so.

    static int[] rotLeft(int[] a, int d) {
        var result = new List<int>();
    
        for (int i = d; i < (a.Length + d); i++)
        {
            result.Add(a[i%a.Length]);
        }      
    
        return result.ToArray();
    }