We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
your time complexity : O(n + n)
your space complexity : n
you can optimize it a little bit with :
time complexity : n + d
space complexity : d
public static void main(String[] args) {
Scanner c = new Scanner(System.in);
int n = c.nextInt();
int d = c.nextInt();
int skipPart[] = new int[d];
int j =0;
for(int i = 0; i < n; i++) {
if(i >= d) {
System.out.print(c.nextInt() + " ");
} else {
skipPart[j] = c.nextInt();
j++;
}
}
for(int i = 0; i < skipPart.length; i++) {
System.out.print(skipPart[i] + " ");
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Left Rotation
You are viewing a single comment's thread. Return to all comments →
your time complexity : O(n + n) your space complexity : n
you can optimize it a little bit with :
time complexity : n + d space complexity : d
public static void main(String[] args) { Scanner c = new Scanner(System.in); int n = c.nextInt(); int d = c.nextInt(); int skipPart[] = new int[d]; int j =0; for(int i = 0; i < n; i++) { if(i >= d) { System.out.print(c.nextInt() + " "); } else { skipPart[j] = c.nextInt(); j++; } } for(int i = 0; i < skipPart.length; i++) { System.out.print(skipPart[i] + " "); } }