forked from Thelalitagarwal/GFG_Daily_Problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerging Details.cpp
More file actions
43 lines (41 loc) · 1.31 KB
/
Merging Details.cpp
File metadata and controls
43 lines (41 loc) · 1.31 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
class Solution {
public:
vector<vector<string>> mergeDetails(vector<vector<string>>& details) {
vector<vector<string>>vv;
for(int i=0;i<details.size();i++)
{
if(details[i][0]!="-")
{
set<string>s;
vector<string>v;
for(int j=1;j<details[i].size();j++)
{
s.insert(details[i][j]);
}
for(int j=i+1;j<details.size();j++)
{
if(details[j][0]!="-")
{
for(int k=1;k<details[j].size();k++)
{
auto pos=s.find(details[j][k]);
if(pos!=s.end())
{
details[j][0]="-";
for(int k=1;k<details[j].size();k++)
{
s.insert(details[j][k]);
}
}
}
}
}
v.push_back(details[i][0]);
for(auto i=s.begin();i!=s.end();i++) v.push_back(*i);
vv.push_back(v);
}
}
sort(vv.rbegin(),vv.rend());
return vv;
}
};