ORIGINAL CODING QUESTION
Rotated ID lookup
A strictly increasing array was cyclically rotated. Return the zero-based target index, or -1 if absent.
Original exercise · medium. Editorial role relevance does not imply a company has asked this question.
Input and output
n, then n rotated distinct values, then target.
Constraints
1 ≤ n ≤ 200; -100 ≤ value ≤ 100. Inputs contain exactly the stated values.
Example 1
Input
5 4 5 1 2 3 2
Output
3
Target 2 is at index 3.
Example 2
Input
3 2 3 1 4
Output
-1
Target 4 is absent.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
At least one half is still sorted.
Hint 2
Compare the target with the sorted half’s bounds.
Hint 3
Discard the half that cannot contain the target.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →