Search in Rotated Sorted Array II
Real-world version: Reading Present in the Rotated LogThe statement here is our own: the same inputs, outputs and technique.
A weather station files temperatures into a ring of fixed size. It files them in non-decreasing order and carries on around the ring, so a reading may equal the one filed before it.
A download starts at whichever slot the reader happens to open at and then walks the ring all the way round. What comes out is log: the non-decreasing run of temperatures shifted round by some number of slots. The shift may be zero, in which case log is simply the run itself.
Return true when the temperature wanted sits in some slot of log, and false otherwise.
Examples
Example 1
- Input
- log = [8, 9, 12, -3, -1, 3], wanted = -1
- Output
- true
The download opened three slots along, so the run 8, 9, 12 comes out first and -3, -1, 3 follows. The temperature -1 sits at index 4.
Example 2
- Input
- log = [4, -1, 4, 4, 4], wanted = -1
- Output
- true
The temperature -1 sits at index 1 of the download.
Example 3
- Input
- log = [8, 9, 12, -3, -1, 3], wanted = 7
- Output
- false
No slot of the download holds 7.
Constraints
- 1 <= log.length <= 5000
- -10^4 <= log[i] <= 10^4
- log is guaranteed to be shifted round at some slot.
- -10^4 <= wanted <= 10^4
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def reading_present(log: list[int], wanted: int) -> bool:public boolean readingPresent(int[] log, int wanted)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's