is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Hi,
- sumit.gupta810 October 04, 2017My code to rotate an array anticlockwise by 'd' times.
Divide the array into 2 parts:-
A[] = [0...d-1] and B[] = [d...n-1]
Steps:-
1. reverse array A.
2.reverse arrayB
3.Reverse the whole array AB.
Code:-
package Arrays.Rotations;
import java.util.Scanner;
public class RotateArrayAnticlockwise {
public static void main(String... a) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter the value of n");
int n = scan.nextInt();
int[] arr = new int[n];
System.out.println("Elements in an array:");
for (int i = 0; i < arr.length; i++) {
arr[i] = scan.nextInt();
}
System.out.println("Enter the value of d:");
int d = scan.nextInt();
rotateArrayAnticlockwiseByReverseMethod(arr, d, n);
scan.close();
printArray(arr);
}
private static void printArray(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
private static void rotateArrayAnticlockwiseByReverseMethod(int[] arr, int d, int n) {
reverse(arr, 0, d - 1);
reverse(arr, d, n - 1);
reverse(arr, 0, n - 1);
}
private static void reverse(int[] arr, int start, int end) {
int temp;
while (start < end) {
temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
}