Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

I don't get how this is Log (n), is this just an exercise to use the binary search, how does traversing using binary search make it better than traversing one by one O(n)?

Worse case it O(n) in both, average case is probably O(n/2)??

Binary search is O(log n), not just O(n).

yea, that makes sense, but we don't know if this list is sorted or not.

I guess binary search only helps when all are sorted except one?

Doesn't matter, it also works if the list is very unsorted.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.