diff --git a/Check_if_Array_Is_Sorted_and_Rotated.java b/Check_if_Array_Is_Sorted_and_Rotated.java new file mode 100644 index 00000000..0c7d98b4 --- /dev/null +++ b/Check_if_Array_Is_Sorted_and_Rotated.java @@ -0,0 +1,20 @@ +public class Check_if_Array_Is_Sorted_and_Rotated { + public static void main(String[] args) { + int nums[] = { 2, 1, 3, 4 }; + System.out.println(check(nums)); + } + + public static boolean check(int arr[]) { + int n = arr.length; + int c = 0; + for (int i = 1; i < n; i++) { + if (arr[i - 1] > arr[i]) { + ++c; + } + } + if (arr[n - 1] > arr[0]) { + ++c; + } + return c <= 1; + } +} \ No newline at end of file diff --git a/Remove_Duplicates_from_Sorted_Array.java b/Remove_Duplicates_from_Sorted_Array.java new file mode 100644 index 00000000..70490d58 --- /dev/null +++ b/Remove_Duplicates_from_Sorted_Array.java @@ -0,0 +1,13 @@ +public class Remove_Duplicates_from_Sorted_Array{ + public static void main(String[] args) { + int arr[]={1,1,2}; + int n=arr.length; + int unique=1; + for(int i=1;i