<p>Let's say I have two arrays:</p>
<blockquote>
<p>int ArrayA[] = {5, 17, 150, 230, 285};</p>
<p>int ArrayB[] = {7, 11, 57, 110, 230, 250};</p>
</blockquote>
<p>Both arrays are sorted and can be any size. I am looking for an efficient algorithm to find if the arrays contain any duplicated elements between them. I just want a true/false answer, I don't care which element is shared or how many.</p>
<p>The naive solution is to loop through each item in ArrayA, and do a <a href="http://en.wikipedia.org/wiki/Binary_search" rel="noreferrer">binary search</a> for it in ArrayB. I believe this complexity is O(m * log n).</p>
<p>Because both arrays are sorted, it seems like there should be a more efficient algorithm.</p>
<p>I would also like a generic solution that doesn't assume that the arrays hold numbers (i.e. the solution should also work for strings). However, the comparison operators are well defined and both arrays are sorted from least to greatest.</p>

Pretend that you are doing a mergesort, but don't send the results anywhere.  If you get to the end of either source, there is no intersection.  Each time you compare the next element of each, if they are equal, there is an intersection.
For example:
```
```
counterA = 0;
counterB = 0;
for(;;) {
    if(counterA == ArrayA.length || counterB == ArrayB.length)
        return false;
    else if(ArrayA[counterA] == ArrayB[counterB])
        return true;
    else if(ArrayA[counterA] < ArrayB[counterB])
        counterA++;
    else if(ArrayA[counterA] > ArrayB[counterB])
        counterB++;
    else
        halt_and_catch_fire();
}
```
```