-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_813_FindAnagramMappings.cpp
More file actions
40 lines (29 loc) · 951 Bytes
/
Copy path_813_FindAnagramMappings.cpp
File metadata and controls
40 lines (29 loc) · 951 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
/* Source - https://www.lintcode.com/problem/find-anagram-mappings/description/
Author - Shivam Arora
*/
#include <bits/stdc++.h>
using namespace std;
vector<int> anagramMappings(vector<int> &A, vector<int> &B) {
unordered_map<int, int> mapping;
vector<int> result;
for (int i = 0; i < B.size(); i++)
mapping[B[i]] = i;
for (int i = 0; i < A.size(); i++)
result.push_back(mapping[A[i]]);
return result;
}
int main()
{
int n;
cout<<"Enter the number of elements: ";
cin>>n;
vector<int> A(n), B(n);
cout<<"Enter elements for first array: ";
for (int i = 0; i < A.size(); i++) cin>>A[i];
cout<<"Enter elements for second array: ";
for (int i = 0; i < B.size(); i++) cin>>B[i];
vector<int> result = anagramMappings(A, B);
cout<<"Anagram mapping from A to B: ";
for (int i = 0; i < result.size(); i++) cout<<result[i]<<" ";
cout<<endl;
}