title: Check if a vector of strings is a substring in one of elements
body: <p>I have a vector of strings like </p>
  
  <pre><code>a1 = ["arp", "live", "strong"]
  
  a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
  </code></pre>
  
  <p>How would I check if armstrong is a substring of strong in a1. using C++</p>
  
  <p>I would do two for loops and check if a string is a substring in a2, but I want an efficient approach.</p>
  
  <pre><code>std::vector&lt;std::string&gt; inArray(std::vector&lt;std::string&gt; &amp;array1, std::vector&lt;std::string&gt; &amp;array2)
  {
      vector&lt;string&gt; result;
      for (string &amp;s : array1)
      {
          for (string &amp;d : array2)
          {
  
              if (s.find(d) != string::npos)
              {
                  cout &lt;&lt; d &lt;&lt; endl;
              }
          }
  
      }
  
      return result;
  
  }
  
  int main() {
  
      vector&lt;string&gt; a = { "arp", "live", "strong" };
      vector&lt;string&gt; b = { "lively", "alive", "harp", "sharp", "armstrong" };
  
      vector&lt;string&gt; result = inArray(a, b);
  
  }
  </code></pre>
  
  <p>Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.</p>
  
  <pre><code>Example 1:
  
  a1 = ["arp", "live", "strong"]
  
  a2 = ["lively", "alive", "harp", "sharp", "armstrong"]
  
  returns ["arp", "live", "strong"]
  </code></pre>