Getting TLE even though the code seems to be working in O(logn) time. First finding pivot in O(logn) and then finding the target also in O(logn). Can’t seem to figure out where the problem lies.

```
public class Solution
{
// DO NOT MODIFY THE LIST
public int search(final List<Integer> a, int b)
{
int start = 0, end = a.size() - 1, mid;
int n = a.size();
int pivot = 0;
while(start<=end)
{
if(a.get(start)<=a.get(end))
pivot = start;
mid = (start+end)/2;
int next = (mid+1)%a.size(), prev = (mid+a.size()-1)%a.size();
if(a.get(mid)<=a.get(next) && a.get(mid)<=a.get(prev))
pivot = mid;
else if(a.get(mid)<=a.get(end))
end = mid - 1;
else
start = mid + 1;
}
start = 0; end = a.size() - 1;
if(b<=a.get((pivot+n-1)%n))
{
start = 0;
end = (pivot+n-1)%n;
}
else if(b>=a.get(pivot))
{
start = (pivot+1)%n;
end = n - 1;
}
while(start<=end)
{
mid = (start+end)/2;
if(a.get(mid)==b)
return mid;
else if(a.get(mid)>b)
end = mid - 1;
else
start = mid + 1;
}
return -1;
}
}
```