# Array Transform | CodeChef Solution

Hello coders, today we are going to solve Array Transform CodeChef Solution whose Problem Code is ARRAYTRM.

Given n numbers, you can perform the following operation any number of times : Choose any subset of the numbers (possibly empty), none of which are 0. Decrement the numbers in the subset by 1, and increment the numbers not in the subset by K.

Is it possible to perform operations such that exactly n – 1 numbers become 0 ?

## Input Format

The first line contains the number of test cases T. 2*T lines follow, 2 for each case. The first line of a test case contains the numbers n and K. The next line contains n numbers, a_1…a_n.

## Output Format

Output T lines, one corresponding to each test case. For a test case, output “YES” if there is a sequence of operations as described, and “NO” otherwise.

Sample Input

``````3
2 1
10 10
3 2
1 2 2
3 2
1 2 3
``````

Sample Output

``````YES
YES
NO``````

## Constraints

• 1 <= T <= 1000
• 2 <= n <= 100
• 1 <= K <= 10
• 0 <= a_i <= 1000

## Solution – Array Transform

### C++

```#include <bits/stdc++.h>
using namespace std;

int main() {

int t;
cin>>t;
while(t--)
{
int n,k;cin>>n>>k;

map<int,int>mp;
for(int i=0;i<n;i++)
{int x;cin>>x;
int z=x%(k+1);
mp[z]++;
}

string  find="NO";
if(mp.size()==2)
{ for(auto i:mp)
{
if(i.second==1)
{
find="YES";
}
}}
if(mp.size()==1)
{
find="YES";
}

cout<<find<<endl;

}
}```

### Python

```T = int(input())
for t in range(T):
N, K = map(int, input().split())
arr = list(map(int, input().split()))
eqClsCount =  * (K+1)

for num in arr:
eqClsCount[num % (K+1)] += 1

eqClsCount.sort(reverse=True)
if N - eqClsCount > 1:
print("NO")
else:
print("YES")```

### Java

```/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{

public static void main(String[] args) throws IOException {

while (testCase-- > 0) {
int n = nk;
int k = nk;
solution(arr, k);
}

}

private static void solution(int arr [], int k){
k++;
int mod [] = new int[k];

for (int i = 0; i < arr.length; i++) {
mod[arr[i]%k]++;
}

for (int val: mod) {
if(val >= arr.length-1){
System.out.println("YES");
return;
}
}

System.out.println("NO");
}
}

}