You are viewing a single comment's thread. Return to all comments →
Trying crazy things to solve it in O(NlogN) My code failed in 3 tests, but i can't think of an small test which it fails, can someone help?
string abbreviation(string a, string b) { int j = 0; map<char, int> dp1, dp2; for(int i = 0;i<a.size();i++) { dp1[a[i]]++; } for(int i = 0;i<b.size();i++) { dp2[b[i]]++; } for(int i = 0;i<b.size();i++) { dp1[b[i]]--; if(dp1[b[i]] < 0) { dp1[char(b[i]+32)]--; if(dp1[char(b[i]+32)] < 0) return "NO"; } } for(int i = 0;i<b.size();i++) { if(dp1[b[i]]>0) return "NO"; } for(int i = 0;i<a.size();i++) { if(dp1[a[i]]>0 && a[i]<='Z') return "NO"; } for(int i = 0;i<a.size();i++) { if(a[i] <= 'Z' && dp2.find(a[i]) == dp2.end()) return "NO"; } for(int i = 0;i<a.size();i++) { if(j < b.size()) { if(a[i] == b[j] || char(a[i]-32) == b[j]) { j++; } } } if(j == b.size()) { return "YES"; } return "NO"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Abbreviation
You are viewing a single comment's thread. Return to all comments →
Trying crazy things to solve it in O(NlogN) My code failed in 3 tests, but i can't think of an small test which it fails, can someone help?