Doubt in increasing decreasing sequence, I cannot understand why all test cases are not passed

this is the code

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
boolean flag=true;
int d=0;
for(int i=1;i<n;i++)
{
d=arr[i]-arr[i-1];
if((arr[i-1]+d)!=arr[i])
{
flag=false;
break;
}
}
System.out.println(flag);
}
}

what is ur approach?

u are taking the difference between the current and prev element
and u are checking the, difference + the prev element

are yar it will always be equal to the current element

jo diff hain wahi to add kar rahe ho prev element

hope this will help u
pls rate my work

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.