a left rotation operation on array of size shifts each of array's elements 1 unit left. example, if left rotations performed on array [1,2,3,4,5], array become [3 ,4 ,5 ,1 ,2] .
my code ran 7 test cases 2 test cases,it showing timeout error,how improve this
using system; using system.collections.generic; using system.io; class solution { static void main(string[] args) { /* enter code here. read input stdin. print output stdout. class should named solution */ string[] tokens = console.readline().split(); int = int.parse(tokens[0]); int b = int.parse(tokens[1]); string[] number = console.readline().split(); int [] array = new int[100000]; for(int i=0;i< a;i++) { array[i]= int.parse(number[i]); } for(int i=1;i<= b;i++) { int d = array[a - 1]; array[a - 1] = array[0]; for(int j=1;j<=a-2;j++) { array[j - 1] = array[j]; } array[a - 2] = d; } for(int k=0;k< a;k++) { console.write(array[k]+" "); } console.readkey(); } }
Comments
Post a Comment