BackeasyBinary Search BinarySearch Arrays

Search in Rotated Sorted Array Solution

Problem Statement

In a secure data pipeline, sensor readings are normally recorded in a strictly ascending order. However, due to a transmission offset, the stream gets circular-shifted at a random index. Given this shifted stream of unique readings, locate a target reading and return its offset position.

Example 1
Input
nums = [4, 5, 6, 7, 0, 1, 2], target = 0
Output
4

Explanation: The element 0 is found at index 4 in the rotated array.

Constraints

  • 1 <= nums.length <= 5000
  • -10^4 <= nums[i], target <= 10^4
  • All values of nums are unique.
  • nums is guaranteed to be rotated at some pivot.
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free