My algorithm skills are lackluster. I created a method to see if two arrays contain the same elements (duplicates don't matter):
one = [1, "taco", 3, 2, :piece, 4, 5, 5, 5, 5] two = [:piece, 2, 5, 4, 1, "taco", 3] def same_elements?(array_one, array_two) return true if ( (array_one - array_two).empty? && (array_two - array_one).empty? ) return false end same_elements?(one, two)
This returns true (which is correct). The problem is I am not sure what the efficiency of this algorithm is? My first guess is O(n^2) since you have to check both a-b and b-a. I know that O(n^2) is pretty terrible. Is there a more efficient way to do this?