Finding common strings among 2 arrays of strings of length 1, sorted alphabetically in O(n) time complexity
Java is not my strong-point, but there are a few things that stand out.


Spacing is non-standard.
There are unnecessary parentheses, e.g. in


(i&lt;a.length)&amp;&amp;(j&lt;b.length)



and


if(!(a[i].equals(prev)))


Optional braces should always be included, e.g. in


if(!(a[i].equals(prev)))
    result++;


Statements should always be on separate lines, e.g. don't do


i++; j++;




There is a more elegant solution using a HashSet&lt;String&gt;, which I believe has the same time complexity.

public int commonTwo(String[] a, String[] b) {
    Set&lt;String&gt; common = new HashSet&lt;&gt;(Arrays.asList(a));
    common.retainAll(new HashSet&lt;&gt;(Arrays.asList(b)));
    return common.size();
}