-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDivision.java
More file actions
36 lines (33 loc) · 900 Bytes
/
ArrayDivision.java
File metadata and controls
36 lines (33 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
public class ArrayDivision{
public static void main(String[] args) {
int k = 6;
int[] array = {9, 7, 5, 3};
System.out.println(check(array,k));
}
public static boolean check(int[] array, int k){
int n = array.length;
if(n%2!=0){
return false;
}
HashMap<Integer,Integer> map = new HashMap<>();
int rem;
for (int i=0;i<n;i++) {
rem = array[i]%k;
if(!map.containsKey(rem))
{
map.put(rem,0);
}
map.put(rem,map.get(rem)+1);
}
if(map.containsKey(0) && map.get(0)%2!=0){
return false;
}
for(int i=1;i<=k/2;i++){
if(map.containsKey(i)){
if(map.get(i)!=map.get(k-i)) return false;
}
}
return true;
}
}