-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoOfRotations.java
More file actions
44 lines (33 loc) · 843 Bytes
/
NoOfRotations.java
File metadata and controls
44 lines (33 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package Arrays;
import java.util.Scanner;
public class NoOfRotations {
public static void main(String[] args) {
System.out.println("Enter no of test cases :");
Scanner sc=new Scanner(System.in);
int T=sc.nextInt();
long[] array;
while(T-->0){
System.out.println("Enter length of array ");
int n=sc.nextInt();
array=new long[n];
System.out.println("Enter array elements");
for(int i=0;i<array.length;i++){
array[i]=sc.nextLong();
}
System.out.println("No of rotation==>"+noOfRotation(array,n));
}
}
public static int noOfRotation(long[] array,int size){
int rotations=0;
long min=array[0];
for(int i=1;i<size;i++){
if(min>array[i]){
min=array[i];
rotations=i;
}
}
if(array[0] == array[size-1] && min == array[0])
return size-1;
return rotations;
}
}