Created
May 24, 2022 07:58
-
-
Save ahangarha/449f4859a2dcc024f8d3594401724da9 to your computer and use it in GitHub Desktop.
DSA - Are they the "same"?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def comp(array1, array2) | |
return false if array1.nil? || array2.nil? | |
hash1 = {} | |
hash2 = {} | |
array1.each do |a| | |
hash1[a] = hash1[a].nil? ? 1 : hash1[a] + 1 | |
end | |
array2.each do |a| | |
hash2[a] = hash2[a].nil? ? 1 : hash2[a] + 1 | |
end | |
hash1.each do |key, value| | |
return false unless hash2[key ** 2] == value | |
end | |
true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment