-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMayContest1.java
More file actions
42 lines (38 loc) · 918 Bytes
/
MayContest1.java
File metadata and controls
42 lines (38 loc) · 918 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
37
38
39
40
41
42
package techgig;
import java.io.*;
import java.util.HashSet;
import java.util.Set;
public class MayContest1
{
public static String partition(int[] input1)
{ boolean validInput = true;
for(int i = 0; i < input1.length; i++) {
if(input1[i] <= 0) {
validInput = false;
break;
}
}
if(validInput) {
Set<Integer> s1 = new HashSet<Integer>();
Set<Integer> s2 = new HashSet<Integer>();
s1.add(0);
for(int i = 0; i < input1.length; i++) {
/* loop over s1 and add to s2 */
for(Integer x : s1) {
s2.add(Math.abs(input1[i] + x));
s2.add(Math.abs(input1[i] - x));
}
s1.clear();
s1.addAll(s2);
s2.clear();
}
return s1.contains(0) ? "Yes" : "No";
} else {
return "Invalid";
}
}
public static void main(String[] args) {
int[] array = {2,3,5,7,8,1,4,9,6,10,11};
System.out.println(partition(array));
}
}