-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSortUnsortedarray.java
More file actions
50 lines (42 loc) · 1.01 KB
/
Copy pathSortUnsortedarray.java
File metadata and controls
50 lines (42 loc) · 1.01 KB
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
49
50
import java.util.Arrays;
public class SortUnsortedarray {
public static int findUnsortedSubarray(int[] nums) {
int arr1[]=nums.clone();
Arrays.sort(arr1);
for(int l:arr1){
System.out.print(l+" ");
} System.out.println();
int i=0;
int j=nums.length-1;
for(int l:nums){
System.out.print(l+" ");
}
System.out.println();
while(i<nums.length){
if(nums[i]==arr1[i]){
i++;
}
else{
break;
}
}
while(j>0){
if(nums[j]==arr1[j]){
j--;
}
else{
break;
}
}
System.out.println(i+" "+j);
if(i>j)
return 0;
else{
return j-i+1;
}
}
public static void main(String[] args) {
int nums[]={1,3,4};
System.out.println(findUnsortedSubarray(nums));
}
}