Problem
The integer array entries was formed from a non-decreasing array by choosing a split position r and moving the prefix before r after the remaining entries. The split satisfies 0 <= r < entries.length, so it may also leave the array unchanged. Values are allowed to repeat.
Given an integer key, return whether the received array contains it. Design the search to minimize the operations it performs.
Examples
Example 1
Input: entries = [3,3,4,1,2,3], key = 1
Output: true
This is a rotation of [1,2,3,3,3,4], and it contains the requested value.
Example 2
Input: entries = [5,5,5,5], key = 4
Output: false
All entries are 5, so the key is absent.
Constraints
-
1 <= entries.length <= 5000
-
-10^4 <= entries[i] <= 10^4
-
The array is a rotation of a non-decreasing integer array.
-
-10^4 <= key <= 10^4
Optional Follow-up
How does allowing repeated values affect the runtime complexity compared with a rotated array of distinct values? Explain why.