-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotated_count_rotated_array.java
More file actions
48 lines (43 loc) · 940 Bytes
/
rotated_count_rotated_array.java
File metadata and controls
48 lines (43 loc) · 940 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
45
46
47
48
/*
Input -> 5
6 5 3 2 9
Output -> 6 5 3 2 9
3
2 9 6 5 3
*/
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int i,j,temp,d=0,count=0,min;
int[] ar=new int[n];
for(i=0;i<n;i++)
ar[i]=scan.nextInt();
for(i=0;i<n;i++)
System.out.print(ar[i]+" ");
min=Integer.MAX_VALUE;
for(i=0;i<n;i++)
{
if(min>ar[i])
{
min=ar[i];
d=i;
}
}
for(i=0;i<d;i++)
{
temp=ar[0];
for(j=1;j<n;j++)
ar[j-1]=ar[j];
ar[n-1]=temp;
count++;
}
System.out.println();
System.out.println(count);
for(i=0;i<n;i++)
System.out.print(ar[i]+" ");
}
}