 # Getting an error which says solution might fail for large test cases

Tags: #<Tag:0x00007f1826a4d298>

#1

I have run a code for this problem which runs in O(logN) time. On submitting the code, I get 48 points & it says your solution might be failing for larger test cases. Also, it doesn’t give which test cases.

Has anyone seen this error before for this problem? Please help me to move in correct direction in order to solve this problem.

Please find the code snippet written by me for this problem below:

``````public class Solution {
// DO NOT MODIFY THE LIST. IT IS READ ONLY
public int search(final List<Integer> A, int B) {

int start = 0;
int N = A.size();
int end = A.size() - 1;
int result = -1;
int minValueIndex = -1;

while (start <= end) {

int mid = (start + end) / 2;
int previousIndex = (mid + N - 1) % N;
int nextIndex = (mid + 1) % N;

if (A.get(start) <= A.get(end)) {
minValueIndex = start;
break;
} else if (A.get(mid) <= A.get(previousIndex) && A.get(mid) <= A.get(nextIndex)) {
minValueIndex = mid;
break;
} else if (A.get(mid) <= A.get(end)) {
end = mid - 1;
} else if (A.get(mid) >= A.get(start)) {
start = mid + 1;
}
}

start = 0;
end = A.size() - 1;

if (A.get(minValueIndex) == B) {
return minValueIndex;
}

if (B >= A.get(0)) {
end = minValueIndex - 1;
} else {
start = minValueIndex + 1;
}

while (start <= end) {

int mid = (start + end) / 2;

if (A.get(mid) == B) {
result = mid;
break;
} else if (A.get(mid) < B) {
start = mid + 1;
} else if (A.get(mid) > B) {
end = mid - 1;
}
}

return result;
}
``````

}