You are viewing a single comment's thread. Return to all comments →
Since this is mentioned inside sorting problems, this should be done in O(log(N) using binary search.
int introTutorial(int V, vector arr) {
int start = 0; int end = arr.size() - 1; while(true) { int middle = (end + start) / 2; // integer division in C++ if(arr[middle] == V) return middle; else if(arr[middle + 1] == V) return middle + 1; else if(V < arr[middle]) end = middle; else start = middle; }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Intro to Tutorial Challenges
You are viewing a single comment's thread. Return to all comments →
Since this is mentioned inside sorting problems, this should be done in O(log(N) using binary search.
int introTutorial(int V, vector arr) {
}