-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconstruct-the-set.java
More file actions
45 lines (31 loc) · 878 Bytes
/
construct-the-set.java
File metadata and controls
45 lines (31 loc) · 878 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
// Akash Yadav
// @Hudson Lane, Delhi
// 17th June 18
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class TestClass{
//https://www.hackerearth.com/challenge/competitive/june-circuits-18/algorithm/construct-the-set-7a9a6be2/
public static Scanner scn = new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception{
int N = scn.nextInt();
int M = scn.nextInt();
int D = scn.nextInt();
int[] S = new int[M];
int[] sorted = new int[M];
for(int i = 0; i < M; i++){
S[i] = scn.nextInt();
sorted[i] = S[i];
}
Arrays.sort(sorted);
HashSet<Integer> ans = new HashSet<>();
for(int i = 0; i < N; i++)
ans.add(sorted[i]);
for(int data : S){
if(ans.contains(data))
System.out.print(data + " ");
}
System.out.println();
}
}