Skip to content

Instantly share code, notes, and snippets.

@omas-public
Last active June 9, 2016 06:56
Show Gist options
  • Save omas-public/e162dcc807f29803fed05c75a85129fe to your computer and use it in GitHub Desktop.
Save omas-public/e162dcc807f29803fed05c75a85129fe to your computer and use it in GitHub Desktop.
(function(stdin) {
var inputs = stdin.toString().trim().split('\n');
var nm = inputs[0].split(' ').map(Number);
var s = inputs[1].slice(0, nm[0] + 1).split('');
var t = inputs[2].slice(0, nm[1] + 1).split('');
var hashMap= function(a) {
return a.reduce(function(map, key) {
map[key] = map[key] + 1 || 1;
return map;
}, {});
};
var result = (function(os, ot) {
return Object.keys(ot)
.map(function(key) {
return ot[key] - (os[key] || 0);
})
.filter(function(v) {
return v >= 0;
})
.reduce(function(a, b) {
return a + b;
});
})(hashMap(s), hashMap(t));
console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment