Last active
July 25, 2020 16:09
-
-
Save coreyjs/b728fd5bc7ce412a6732eed44b854886 to your computer and use it in GitHub Desktop.
Compare two strings to see if there is a subset
This file contains hidden or 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
| #!/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