See, i=1,j=1, in checking a[i]!=a[j] , both i and j are 1, so a[1]!=a[1] is false; it breaks; hence executed once; similarly , for i=2; j starts with 2, comparison fails, it breaks; so only one time the inner loop gets executed for every value of outer loop;
hence O(n)