I wrote a program in C# and I am getting Time Limit Exceed in last 3 test Cases. What is wrong with my code? Need Help! I getting error when there is more number of- Test Case- 20 No of Array Elements and No of Rotations- 9384 208886
static void ShowResult(int[] A,int k,int n)
{
int rcount = 1;
while (rcount <= k)
{
int temp = A[n - 1];
for (int i = n - 1; i != 0; i--)
{
A[i] = A[i - 1];
}
A[0] = temp;
rcount++;
}
foreach (var res in A)
{
Console.Write(res+" ");
}
Console.WriteLine();
}
static void Main(String[] args)
{
int N;
int K;
int flag=1;
int T=Convert.ToInt32(Console.ReadLine());
while(flag<=T)
{
string str1=Console.ReadLine();
string[] strarr1=new string[2];
strarr1=str1.Split(' ',(char)2);
N=Convert.ToInt32(strarr1[0]);
K=Convert.ToInt32(strarr1[1]);
string str2=Console.ReadLine();
int[] A=Array.ConvertAll(str2.Split(' '),int.Parse);
ShowResult(A, K, N);
flag++;
}
[enter image description here][1]
Sample Input
1
5 2
1 2 3 4 5
Sample Output
4 5 1 2 3
Explanation
Here 1 is, no of test case. Here 5 and 2 are no of array is 5 and no of rotation is 2. For first rotation: 51234 For 2nd Rotation: 45123 So output will be 45123