Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the "same" elements, with ...
For further actions, you may consider blocking this person and/or reporting abuse
Python solution
Solution in Haskell:
Edit:
I wanted to implement the O(a + b) solution in Haskell as well:
Why use
all same
? Can't you directly testmap (^2) (sort a) == sort b
?Wasn't aware that Haskell's equality operator did deep comparision, but that makes sense. Thanks!
I'd probably rewrite this with the O(a + b) algorithm from the other solution.
It's not really deep comparison, it uses the Eq class (==) function. For the primitives, it's by value. For ADTs that derive Eq, it checks equality for all of the values in the ADT, which functions that same as deep comparison.
The main point to keep in mind with this one is that all values in
b
must be accounted for, as we see with the test case with36100
as a value. Additionally, we can't use a set for this problem since values may show up in eithera
orb
multiple times, so that's out. So instead, we can calculate the frequency of occurrences of values instead, which leads to thisO(a + b)
solution:JS solution
*fixed
My Swift solution :
My solution in JavaScript
C++ solution
Ruby
Python:
Php solution
Anyone have PHP Solution???