A performance recorder keeps event IDs in a fixed-size circular buffer. The IDs were written in increasing order, but because the buffer wraps around, the array buffer is a sorted list that was rotated: for example [40, 52, 67, 3, 18, 29]. All IDs are different.
Write searchBuffer(buffer, target) that returns the index of target in buffer, or -1 if it is not there.
Use O(log n) time.
Input: buffer = [40,52,67,3,18,29], target = 18 Output: 4
18 is at index 4, in the part after the wrap.
Input: buffer = [40,52,67,3,18,29], target = 50 Output: -1
50 is not in the buffer.
1 <= buffer.length <= 100000buffer is a sorted array rotated by some amount (possibly 0).Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #166 Search a Wrapped Event Buffer. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.