simple-exercises/ruby-exercises/easy-5.rb
# ------------------------------------------------------------------------------
#
#
# In All Strings
# ------------------------------------------------------------------------------
# Check if a short_string is a substring of ALL of the long_strings
In All Strings
Check if a short_string is a substring of ALL of the long_strings
In All Strings Check if a short_string is a substring of ALL of the long_strings
def in_all_strings?(long_strings, short_string)
  long_strings.each do |s|
    in_string = false
    n = s.length - short_string.length
    (0..n).each do |i|
      if s.slice(i, short_string.length) == short_string
        in_string = true
        break
      end
    end
    if in_string == false
      return false
    end
  end
  true
end
def in_all_strings? ( long_strings , short_string ) long_strings . each do | s | in_string = false n = s . length - short_string . length ( 0 .. n ) . each do | i | if s . slice ( i , short_string . length ) == short_string in_string = true break end end if in_string == false return false end end true end
In All Strings
Check if a short_string is a substring of ALL of the long_strings
In All Strings Check if a short_string is a substring of ALL of the long_strings
# sliding window # check each long_string # check each substring of a long string # if equal to short string # if we encounter the shortstring in the substring # then we should move on to the next long string # if we didn't find a substring in this long string # then we know that not all substrings are in the long string
long_strings
<not_specific>
short_string
<not_specific>