Skip to content

Instantly share code, notes, and snippets.

@ahangarha
Created May 24, 2022 07:58
Show Gist options
  • Save ahangarha/449f4859a2dcc024f8d3594401724da9 to your computer and use it in GitHub Desktop.
Save ahangarha/449f4859a2dcc024f8d3594401724da9 to your computer and use it in GitHub Desktop.
DSA - Are they the "same"?
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