You are viewing a single comment's thread. Return to all comments →
bool matching(string a,string b) { for(int i=0;i<10;i++) { if(a[i]=='0' && b[i]=='0') return false; } return true; } long winningLotteryTicket(vector<string> tickets) { long long int n=tickets.size(); unordered_map<string,long long int> s; for(int i=0;i<n;i++) { string x="0000000000"; int z=tickets[i].size(); for(int j=0;j<z;j++) { x[tickets[i][j] -'0']='1'; } s[x]++; } long long int answer=0; for(auto i=s.begin();i!=s.end();i++) { for(auto j=next(i);j!=s.end();j++) { if(matching(i->first,j->first)) answer+=i->second*j->second; } } auto i=s.find("1111111111"); if(i!=s.end()) answer+=(i->second*(i->second-1))/2; return answer; }
Seems like cookies are disabled on this browser, please enable them to open this website
Winning Lottery Ticket
You are viewing a single comment's thread. Return to all comments →