-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMayContest2.java
More file actions
46 lines (39 loc) · 1000 Bytes
/
MayContest2.java
File metadata and controls
46 lines (39 loc) · 1000 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
43
44
45
46
package techgig;
import java.util.ArrayList;
import java.util.List;
public class MayContest2 {
private static int find(int[] input1, int input2) {
List<Integer> houses = new ArrayList<Integer>();
if(input1[0] != 1 && input1[0] != 2) {
return -1;
} else if(input1[0] == 1) {
houses.add(1);
houses.add(0);
} else if(input1[0] == 2) {
houses.add(1);
houses.add(1);
}
for(int i = 1; i < input1.length - 1; i++) {
if(input1[i] == 0 || input1[i] == 1 || input1[i] == 2 || input1[i] == 3) {
int x = input1[i] - houses.get(i) - houses.get(i - 1);
if(x == 0 || x == 1) {
houses.add(x);
} else {
return -1;
}
} else {
return -1;
}
}
int l = houses.size();
if((houses.get(l - 1) + houses.get(l - 2)) != input1[input1.length - 1]) {
return -1;
}
return houses.get(input2 - 1);
}
public static void main(String[] args) {
int[] scores = {1,2,2,2,0};
int house = 4;
System.out.println(find(scores, house));
}
}