Arrays: Left Rotation

  • + 0 comments

    C# this is with basic knowledge

    public static List rotLeft(List a, int d) {

            int length=a.Count()-1;
            int[] newArr = new int[length+1];
    
            for(int i = length;i>-1;i--){
    
                if(i-d<0)
                {                   
                    int j=i-d;                   
                    newArr[length+1+j]=a[i];                      
                }
                else
                {
                    newArr[i-d]=a[i];
                }
            }
            return   newArr.ToList() ;
    }
    

    }