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.
Then, I define a function to compare both IntMap's by (unique) keys.
cmpnumcnt1cnt2=ifcnt1>cnt2thenJustnumelseNothing
It means, if a number num occurs more times in the first list than in the second one, then we are looking for it.
Finally, the program is simple:
main=do-- Build the first IntMap_<-getLinea<-(buildMapM.empty.mapread.words)<$>getLine-- Build the second IntMap _<-getLineb<-(buildMapM.empty.mapread.words)<$>getLine-- Find the differencesletdiffs=M.differenceWithKeycmpba-- PrintputStrLn.unwords.map(show.fst).M.toList$diffs
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Missing Numbers (FP)
You are viewing a single comment's thread. Return to all comments →
Spoiler alert.
First, I use strict IntMap's to efficiently count the number of occurrences of each element in both lists.
Then, I define a function to compare both IntMap's by (unique) keys.
It means, if a number num occurs more times in the first list than in the second one, then we are looking for it. Finally, the program is simple: