-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSymmetricPair.java
More file actions
52 lines (46 loc) · 1.01 KB
/
SymmetricPair.java
File metadata and controls
52 lines (46 loc) · 1.01 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
import java.util.*;
class SymmetricPair
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[][]=new int[n][2];
for(int i=0;i<n;i++)
{
arr[i][0]=sc.nextInt();
arr[i][1]=sc.nextInt();
}
HashMap<Integer,Integer> map=new HashMap<>();
boolean isFound=false;
for(int i=0;i<arr.length;i++)
{
int first=arr[i][0];
int second=arr[i][1];
Integer data=map.get(second);
if(data!=null && data==first)
{
System.out.println(second+" "+first);
isFound=true;
}
else
{
map.put(first,second);
}
}
if(!isFound)
{
System.out.println("Not Found");
}
}
}
// (a,b) (c,d) means c=b and a=d is symetric
// i/o
// 5
// 1 2
// 2 1
// 1 3
// 3 1
// 4 5
// o/p
// 1 2
// 1 3