It can be done in O(log n)
first we search a[2] if not equal to 1 then a[4],a[8], a[16]....
we use two variables for this one which stores a[2n-1] and another which stores a[2n]
let us say that at a[1024]=0 and a[2048]=1
now we have a low and a high now we can apply binary search
complexity
traversing in power of 2 = (log n)
binary search = (log n)
total complexity(log n + log n)=O(log n)