int searchInsert(int A[], int n, int target) {

```
int l = 0;
int r = n-1;
int mid;
//binar search to update search range
while(l<r)
{
mid = (l+r)>>1;
if(A[mid]<target)
l =mid+1;
else
r=mid;
}
return A[l]>=target?l:l+1;
}
```