```
bool search(int A[], int n, int target) {
int left = 0, right = n - 1;
while(left <= right) {
while(A[left] == A[left+1] && left < n)
left++;
while(A[right] == A[right-1] && right >= 0)
right--;
int mid = (left + right)/2;
if(A[mid] == target)
return true;
else {
if(A[left] <= A[mid]) {
if(target < A[mid] && target >= A[left])
right = mid - 1;
else
left = mid + 1;
}
else {
if(target > A[mid] && target <= A[right])
left = mid + 1;
else
right = mid - 1;
}
}
}
return false;
}
```