Rakesh has given an array of integers and you need to find out if the absolute difference of values of any two consecutive array integers is at-most D.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++){
int n,k;int tag=0;
scanf("%d %d",&n,&k);
int integers[n];
for(int j=0;j<n;j++){
scanf("%d",&integers[j]);
}
for(int l=0;l<=n-1;l++){
if(abs(integers[l+1]-integers[l])<=k)tag++;
}
if(tag==n-1) printf("YES\n");
else printf("NO\n");
}
return 0;
}
Comments
Post a Comment