k sorted array
##### Submissions: 544   Accuracy: 30.87%   Difficulty: Easy   Marks: 2

Given an array of n distinct elements. Check whether the given array is a k sorted array or not. A k sorted array is an array where each element is at most k distance away from its target position in the sorted array.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case contains an integer n denoting the size of the array. The next line contains n space separated integers forming the array. The last line contains k.

Output:
Print "Yes" if the array is a k sorted array.
Print "No" if the array is not a k sorted array.

Constraints:
1<=T<=10^5
1<=n<=10^5
1<=a[i]<=10^5
1<=k<=n

Example:
Input:

2
6
3 2 1 5 6 4
2
7
13 8 10 7 15 14 12
3

Output:
Yes
No

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Govil
Author: Ayush Govil 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.