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.
Input:
First line of input contains an integer T, denoting the number of test cases.
First line of each test case contains two integers N and D, denoting the size of the array and value of D respectively.
Second line of each test case contains N integers, which are separated by one space and are the integers for the array.
Output:
Print YES if the absolute difference between any two consecutive integer is at-most D, otherwise print NO
#include <stdio.h> #include <stdlib.h> int main() { int j=0,t,i,n,k; scanf("%d",&t); while(j<t) { scanf("%d %d",&n,&k); int integers[n]; int flag=0; for(i=0;i<n;i++) scanf("%d",&integers[i]); for(i=0;i<n;i++) if(abs(integers[i]-integers[i+1])<=k) flag++; if(flag==(n-1)) printf("\nYES"); else printf("\nNO"); j++; } return 0; }
INPUT_1:
2
5 2
11 12 14 13 15
3 4
11 17 26
OUTPUT:
YES
NO
INPUT_2:
3
6 3
5 3 2 1 5 8
2 2
13 12
2 1
21 26
OUTPUT:
NO
YES
NO
ILLUSTRATION:
Morae! Q
- Find a triplet such that triplet is minimum of all the triplets.
- Rearrange characters in a string such that no two adjacent are same.
- Return the coordinates of all cells in matrix sorted by their distance.
- Function to verify the ISBN number from the book.
- Find out the absolute difference of values of two array integers.
- Rotate the array in the right direction by K steps.
- Find the sequence of moves that wins the game, collect exactly G coins!.
- Calculate the sum of boundary elements of a matrix.
- Find the total number of ways to reach the tree house.
- Compute profit and loss of a product.
- Find the total expense of purchased items.
- Determine the maximum sequence weight.
- Find the person’s birth year is a leap year or not.
- Find the inner rating with the displayed rating.
- Find if angles are valid to form a triangle.
- Find out the winner of the game from the given statistics.
- Verify the tag to determine if one needs to arrest or allow the vehicle.
- Find the largest hexadecimal number.
- Group up all anagrams together from given words.
- Return all anagrams from the given words.