Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dheeraj_Kriplani_D_20 #142

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Check_if_Array_Is_Sorted_and_Rotated.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
13 changes: 13 additions & 0 deletions Remove_Duplicates_from_Sorted_Array.java
Original file line number Diff line number Diff line change
@@ -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<n;i++){
if(arr[i]!=arr[i-1]){
arr[unique++]=arr[i];
}
}
System.out.println(unique);
}
}