Skip to content

Instantly share code, notes, and snippets.

@mwangepatrick
Created July 31, 2022 13:10
Show Gist options
  • Save mwangepatrick/da191ff7716e88a30e201443909cef54 to your computer and use it in GitHub Desktop.
Save mwangepatrick/da191ff7716e88a30e201443909cef54 to your computer and use it in GitHub Desktop.
/* package whatever; // don't place package name! */
import java.io.*;
public class myCode
{
public static void main (String[] args) throws java.lang.Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();
System.out.println(input);
int n = Integer.valueOf(input);
int [] arr = new int [n];
String [] strArr = br.readLine().split("\\s+");
for(int i = 0; i < n; i ++) {
arr[i] = Integer.valueOf(strArr[i]);
}
smooth(arr);
}
public static void smooth(int [] arr) {
int n = arr.length;
boolean isSmooth = true;
for(int i = 0; i < n - 1; i++){
if(Math.abs(arr[i] - arr[i+1]) > 1){
isSmooth = false;
break;
}
}
if(isSmooth) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment