Skip to content

Instantly share code, notes, and snippets.

@coreyjs
Last active July 25, 2020 16:09
Show Gist options
  • Select an option

  • Save coreyjs/b728fd5bc7ce412a6732eed44b854886 to your computer and use it in GitHub Desktop.

Select an option

Save coreyjs/b728fd5bc7ce412a6732eed44b854886 to your computer and use it in GitHub Desktop.
Compare two strings to see if there is a subset
#!/bin/ruby
require 'json'
require 'stringio'
require 'set'
# Complete the twoStrings function below.
#s1, s2: two strings to analyze .
def twoStrings(s1, s2)
set1 = Set.new
set2 = Set.new
s1.each_char { |c| set1 << c}
s2.each_char { |c| set2 << c}
s3 = set1 & set2
s3.empty? ? 'NO' : 'YES'
end
fptr = File.open(ENV['OUTPUT_PATH'], 'w')
q = gets.to_i
q.times do |q_itr|
s1 = gets.to_s.rstrip
s2 = gets.to_s.rstrip
result = twoStrings s1, s2
fptr.write result
fptr.write "\n"
end
fptr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment