Arrays: Left Rotation

  • + 5 comments

    Can any one please tell me why the below code is timing out for large data set:

    for(int j=0;j<k;j++)
            {
            for(int current=n-1;current>=0;current--)
            {
               if(current!=0)
               {
                   if(temp!=0)
                   {
                     
                a[current-1]= a[current-1]+temp;
                       temp= a[current-1]-temp;
                       a[current-1]=a[current-1]-temp;
                   }
                   else
                   {
                       temp=a[current-1];
                       a[current-1]=a[current];//for the first time
                      
                   }
                
               
               }
                else//when current reaches the first element
                {
                    a[n-1]=temp;
                    
                }  
            }
                
            }
            Console.WriteLine(string.Join(" ",a));