A sensor panel stores readings in a ring buffer. The readings were written in non-decreasing order and the buffer wrapped, so readings is a sorted list rotated by some amount. Unlike timestamps, readings can repeat, as in [4, 4, 5, 1, 2, 4, 4].
Write hasReading(readings, target) that returns true if target appears in readings and false otherwise.
It should be O(log n) when there are few repeats. When repeats hide which half is sorted, it may slow down, but it must stay correct.
Input: readings = [4,4,5,1,2,4,4], target = 1 Output: true
1 sits right after the wrap.
Input: readings = [4,4,5,1,2,4,4], target = 3 Output: false
No reading is 3.
1 <= readings.length <= 5000readings is a non-decreasing array rotated by some amount.-10^4 <= readings[i], target <= 10^4Run 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 #168 Wrapped Buffer With Repeats. 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.