Haskell intersection

Revision en1, by haleyk100198, 2017-03-18 09:21:53

Recently I have been practicing Haskell on CSAcademy, and I was implementing this problem : https://csacademy.com/contest/interview-archive/#task/array-intersection/

Intuitively I tried to use the predefined intersection function to solve the task, yet it does not fit the problem's requirement as it only considers the frequency of the elements showing up in the first list. After googling for a while I found the replacement using xs \ (xs \ ys), yet O(N^2) is not good enough to solve the problem. While the problem could be solved in O(N) by hashing as suggested in the statement, I wonder if there is a predefined way to cope with this task in a Haskell function way? (Dear Haskell god, please spare me from implementing some of the functions)

Tags haskell, csacademy, intersection

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English haleyk100198 2017-03-18 09:21:53 851 Initial revision (published)