Skip to content

Instantly share code, notes, and snippets.

@thmain
Created August 26, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/f90642f37931001dcc209a927be0100c to your computer and use it in GitHub Desktop.
Save thmain/f90642f37931001dcc209a927be0100c to your computer and use it in GitHub Desktop.
public class FirstDecreasingBruteForce {
public static void find(int [] a){
for (int i = 1; i <a.length ; i++) {
if(a[i]<a[i-1]){
System.out.println("First Element from where elements starts decreasing: " + a[i-1]);
return;
}
}
//if you have reached here , means no decreasing
System.out.println("Array does not have a decreasing point, Max element is : "+ a[a.length-1]);
}
public static void main(String[] args) {
// int [] a = {1,2,4,6,11,15,19,20,21,31,41,51,55,46,35,24,18,14,13,12,11,4,2,1};
int [] a = {1,2,3};
find(a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment