-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMissingMembers.java
More file actions
59 lines (50 loc) · 1.38 KB
/
MissingMembers.java
File metadata and controls
59 lines (50 loc) · 1.38 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.*;
public class MissingMembers {
public static boolean check(int[] arr, int toCheck) {
boolean flag = false;
for (int num: arr) {
if (toCheck == num) {
flag = true;
return flag;
}
}
return flag;
}
public static void printArray(int[] a) {
for (int i = 0; i < a.length; i++)
System.out.print(a[i] + " ");
System.out.println();
}
public static int[] merge(int[] input, int[] missing ) {
int[] temp = new int[input.length+ missing.length];
int left = 0, right = 0, it = 0;
while (left < input.length && right < missing.length) {
if (input[left] <= missing[right])
temp[it++] = input[left++];
else
temp[it++] = missing[right++];
}
while (left < input.length) temp[it++] = input[left++];
while (right < missing.length) temp[it++] = missing[right++];
return temp;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numOfMembers,numOfRemaining;
numOfMembers = sc.nextInt();
sc.nextLine();
numOfRemaining = sc.nextInt();
sc.nextLine();
int [] missing = new int[numOfMembers - numOfRemaining];
int [] input = new int[numOfRemaining];
for (int i = 0; i < numOfRemaining; i++)
input[i] = sc.nextInt();
sc.nextLine();
int k=0;
for (int j = 1; j <= numOfMembers; j++)
if (check(input,j) == false) {
missing[k++] = j;
}
printArray(merge(input,missing));
}
}