Skip to content

Instantly share code, notes, and snippets.

@layonthebeech
Created September 29, 2016 20:18
Show Gist options
  • Save layonthebeech/4bd4469be8bad9c3e2f5f40d6583d712 to your computer and use it in GitHub Desktop.
Save layonthebeech/4bd4469be8bad9c3e2f5f40d6583d712 to your computer and use it in GitHub Desktop.
Ransom note question on hackerrank solution
function main() {
var m_temp = readLine().split(' ');
var m = parseInt(m_temp[0]);
var n = parseInt(m_temp[1]);
magazine = readLine().split(' ');
ransom = readLine().split(' ');
var arr = []
var dict = {}
for(var i = 0; i < magazine.length; i++) {
if(dict[magazine[i]]) {
dict[magazine[i]] +=1;
} else {
dict[magazine[i]] = 1;
}
}
for(var i = 0; i < ransom.length; i++) {
if(dict[ransom[i]] && dict[ransom[i]] > 0) {
dict[ransom[i]]--;
arr.push(true);
}
}
//console.log(arr, ransom, Object.keys(arr).length === ransom.length ? 'Yes':'No')
console.log(arr.length === ransom.length ? 'Yes':'No')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment