-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path37.cpp
More file actions
29 lines (28 loc) · 652 Bytes
/
Copy path37.cpp
File metadata and controls
29 lines (28 loc) · 652 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
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
//program to find common element in all rows of matrix in O(mn) time (one traversal).
int m, n;
cin>>m>>n;
int arr[m][n];
for(int i=0;i<m;i++){
for(int j=0;j<n;j++)cin>>arr[i][j];
}
map<int, int> mp;
for(int i=0;i<n;i++){
mp[arr[0][i]] = 1;
}
for(int i=1;i<m;i++){
for(int j=0;j<n;j++){
if(mp[arr[i][j]]==i){
mp[arr[i][j]] = i + 1;
if(i==m-1){
cout<<arr[i][j]<<" ";
}
}
}
}
cout<<endl;
return 0;
}