Practice arena
C++17·2 s·128 MB
SearchingChallenge
Search rotated data
Locate target in a strictly increasing array rotated at an unknown pivot. Return its zero-based index or -1.
Input
- — The first line contains T.
- — Each case contains n and target, followed by n distinct integers.
Output
Print the target index or -1.
Technique
identify the sorted half
Target
O(log n)
Constraints & sample
- 1 ≤ n ≤ 200,000
- All array elements are distinct
Sample input
3 7 0 4 5 6 7 0 1 2 7 3 4 5 6 7 0 1 2 1 1 1
Expected output
4 -1 0
Before you submit
- Test the smallest valid input and one awkward edge case.
- Keep the solution within O(log n).
- Match spacing and line breaks exactly before checking 9 hidden cases.
Draft saved locally · 466 / 30,000
Ln 1, Col 1Spaces: 4UTF-8LFC++17
Visible testcases
Editable and stored only in this browser. Hidden judge cases never change.
Checking your session…
Run checks Sample · Submit checks 9 hidden cases
Run the sample first, then send your solution through 9 hidden cases.
Code runs in an isolated Judge0 environment. Drafts and custom visible cases stay on this device; submission metadata and progress sync to MongoDB.