Skip to main content
7 of 7
deleted 29 characters in body
sporkl
  • 6.9k
  • 1
  • 31
  • 64

Test if a string can be made with substrings!

Given a string s and an array/list l, determine whether or not s can be made with parts from l.

For example, if the string is "Hello, world!" and the list is [' world!', 'Hello,'], then the program/function should return a truthy value, because you can arrange the list to form the string. The following list would also return a truthy value: ['l', 'He', 'o, wor', 'd!']. Just imagine the 'l' filling in where it needs to in he string. So yes, you may repeat elements of the list to form the string. If it cannot form the string, it should return a falsy value. Standard methods of IO, standard loopholes apply.

Test cases:

Input (In the form of s, l) Output (1 if possible, 0 if impossible) "Hello, world!", ["l", "He", "o, wor", "d!"] 1 "la lal al ", ["la", " l", "al "] 1 "this is a string", ["this should return falsy"] 0 "thi is a string", ["this", "i i", " a", " string"] 0 "aaaaa", ["aa"] 0 "foo bar foobar", ["foo", "bar", " ", "spam"] 1 "ababab", ["a","ba","ab"] 1 "", ["The string can be constructed with nothing!"] 1 
sporkl
  • 6.9k
  • 1
  • 31
  • 64