We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functiongameOfThrones(s){//strMap stores each letter and its frequencyconststrMap=newMap([]);//oddSet stores the alphabet that appears an odd number of times in the stringconstoddSet=newSet([]);for(leti=0;i<s.length;i++){//add every unique alphabet in the strMap along with the number of times it appears in the string.strMap.set(s[i],(strMap.get(s[i])??0)+1);if(strMap.get(s[i])%2!==0){//if the frequency of the alphabet modded with 2 is not zero, it is odd and must be added to the oddSetoddSet.add(s[i])}else{//if its occurence is divisible by 2, it is even and we remove it from the oddSetoddSet.delete(s[i])}}
if (oddSet.size > 1) return "NO"
return "YES"
}
`
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Game of Thrones - I
You are viewing a single comment's thread. Return to all comments →
Javascript:
} `