Repository navigation
Expand file tree
/
Copy pathQuadrupleProduct.java
More file actions
104 lines (91 loc) · 2.51 KB
/
Copy pathQuadrupleProduct.java
File metadata and controls
104 lines (91 loc) · 2.51 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.*;
// a*b=c*d;
// n*n Time complexity
class QuadrupleProduct
{
static class Pair{
int first;
int second;
public Pair(int first,int second)
{
this.first=first;
this.second=second;
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
HashMap<Integer,Pair> map=new HashMap<>();
boolean isFound=false;
for(int x=0;x<n;x++)
{
for(int y=x+1;y<n;y++)
{
int productVal=arr[x]*arr[y];
if(map.containsKey(productVal))
{
isFound=true;
Pair p=map.get(productVal); //index store krenga
System.out.println(arr[p.first]+" "+arr[p.second]+" "+arr[x]+" "+arr[y]);
}
else
{
map.put(productVal,new Pair(x,y));
}
}
}
if(!isFound)
{
System.out.println("Not found");
}
}
}
// i/o
// 6
// 1 2 6 3 4 12
// o/p
// 1 12 2 6
// 1 6 2 3
// 2 12 6 4
// 1 12 3 4
// class QuadrupleProduct
// {
// public static void main(String[] args) {
// Scanner sc=new Scanner(System.in);
// int n=sc.nextInt();
// int arr[]=new int[n];
// for(int i=0;i<n;i++)
// {
// arr[i]=sc.nextInt();
// }
// HashMap<Integer,HashMap<Integer,Integer>> map=new HashMap<Integer,HashMap<Integer,Integer>>();
// HashMap<Integer,Integer> innerMap = new HashMap<Integer,Integer>();
// boolean isFound=false;
// for(int x=0;x<n;x++)
// {
// for(int y=x+1;y<n;y++)
// {
// int productVal=arr[x]*arr[y];
// if(map.containsKey(productVal))
// {
// isFound=true;
// HashMap<Integer,Integer> p=map.get(productVal); //index store krenga
// System.out.println(p.getKey()+" "+p.getValue()+" "+arr[x]+" "+arr[y]);
// }
// else
// {
// map.put(productVal,.put(x,y));
// }
// }
// }
// if(!isFound)
// {
// System.out.println("Not found");
// }
// }
// }