Given an array of $N$ integers in which the first $n$ of them are positive and the rest are negative, can we find $n$ in O(log$n$) time?

81 Views Asked by At

Binary search will find $n$ in O(log$N$) time, is there a way to do it in O(log$n$) time?

I was thinking on the lines:
Check every $2^i$th number till you encounter a negative integer. If, at the $k$th step we encounter a negative integer, perform the same procedure starting from the $2^{k−1}$th number.
However, I'm not sure of the time complexity of this algorithm.