You are viewing a single comment's thread. Return to all comments →
My cpp code takes too long for large input, any help optimizing it?
#include<iostream> using namespace std; void checkMagazine(string mag[],string note[],int m,int n) { int temp=0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(note[i]==mag[j]){ mag[j]="-"; temp++; break; } } } if(temp==n) cout<<"Yes\n"; else cout<<"No\n"; } int main(){ int m,n; cin>>m>>n; string magazine[m],note[n]; for(int i=0;i<m;i++) cin>>magazine[i]; for(int i=0;i<n;i++) cin>>note[i]; checkMagazine(magazine,note,m,n); //checkMagazine }
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
My cpp code takes too long for large input, any help optimizing it?