We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
That is correct -- but you can perform two linear searches and throw out the first hit of the second search if and when it matches the result of the first search. Alternatively, one may search from back to front.
Since the original order is to be kept, I am unaware of alternatives to linear search. By using the two-pointer technique, I arrive at O(nlogn + n + n) = O(nlogn).
Ice Cream Parlor
You are viewing a single comment's thread. Return to all comments →
That is correct -- but you can perform two linear searches and throw out the first hit of the second search if and when it matches the result of the first search. Alternatively, one may search from back to front.
Since the original order is to be kept, I am unaware of alternatives to linear search. By using the two-pointer technique, I arrive at O(nlogn + n + n) = O(nlogn).