What would the Big O be of a nested for loop with an Any() inside it?
<p>This questions is basically a follow-on from my <a href="https://stackoverflow.com/a/38332524/542251">answer here</a>. I really wanted to say what the Big-O of this algorithm would be, but I wasn't sure my claim was completely sound.</p>

<p>So given two arrays:</p>

<pre><code>B = [ "Hello World!", "Hello Stack Overflow!", "Foo Bar!", "Food is nice...", "Hej" ]
A = [ "World", "Foo" ]
</code></pre>

<p>what is the Big O of:</p>

<pre><code>List&lt;string&gt; results = new List&lt;string&gt;();
foreach (string test in B)
{
   if (A.Any(a =&gt; test.Contains(a))
      results.Add(test);
}
</code></pre>

<p>I believe it to be somewhere between <code>O(n)</code> and <code>O(n^2)</code> as it depends where in the result the <code>Any()</code> matches...</p>