Last active
October 21, 2021 11:16
-
-
Save janvichhabra/d86f9bd1b015cde179454f4d00d16899 to your computer and use it in GitHub Desktop.
pepcoding.com 21/10/21 getCommonElements-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unordered_map> | |
using namespace std; | |
int main(){ | |
int n,m; | |
cin >> n; | |
int arr1[n]; | |
unordered_map<int,int> mp; | |
for(int i=0;i<n;i++){ | |
cin >> arr1[i]; | |
mp[arr1[i]]++; | |
} | |
cin >> m; | |
int arr2[m]; | |
for(int i=0;i<m;i++){ | |
cin >> arr2[i]; | |
if(mp.find(arr2[i])!=mp.end() && mp[arr2[i]]!=0){ | |
cout << arr2[i] << endl; | |
mp[arr2[i]]--; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
n1 = int(input()) | |
arr1=[] | |
for i in range(n1): | |
arr1.append(int(input())) | |
n2 = int(input()) | |
arr2=[] | |
for i in range(n2): | |
arr2.append(int(input())) | |
hm={} | |
for val in arr1: | |
if val in hm: | |
hm[val]=hm.get(val)+1 | |
else: | |
hm[val]=1 | |
for val in arr2: | |
if val in hm and hm.get(val)>0: | |
print(val) | |
hm[val]=hm.get(val)-1 | |
if __name__ == '__main__': | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
int main(){ | |
//write your code here | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
n1 = int(input()) | |
arr1=[] | |
for i in range(n1): | |
arr1.append(int(input())) | |
n2 = int(input()) | |
arr2=[] | |
for i in range(n2): | |
arr2.append(int(input())) | |
#write your code here | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment