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.
// Complete the circularArrayRotation function below.
static int[] circularArrayRotation(int[] a, int k, int[] queries) {
int last=a[a.length-1];
for(int i=a.length-2;i>=0;i--)
{
a[i+1]=a[i];
}
a[0]=a[last];
for(int i=0;i<queries.length;i++)
{
int c=queries[i];
int m=a[c];
return m;
break;
}
}
private static final Scanner scanner = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
String[] nkq = scanner.nextLine().split(" ");
int n = Integer.parseInt(nkq[0]);
int k = Integer.parseInt(nkq[1]);
int q = Integer.parseInt(nkq[2]);
int[] a = new int[n];
String[] aItems = scanner.nextLine().split(" ");
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
for (int i = 0; i < n; i++) {
int aItem = Integer.parseInt(aItems[i]);
a[i] = aItem;
}
int[] queries = new int[q];
for (int i = 0; i < q; i++) {
int queriesItem = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");
queries[i] = queriesItem;
}
int[] result = circularArrayRotation(a, k, queries);
for (int i = 0; i < result.length; i++) {
bufferedWriter.write(String.valueOf(result[i]));
if (i != result.length - 1) {
bufferedWriter.write("\n");
}
}
bufferedWriter.newLine();
bufferedWriter.close();
scanner.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Circular Array Rotation
You are viewing a single comment's thread. Return to all comments →
sir can you please help me.Whats wrong with my code ??
import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.regex.*;
public class Solution {
}