Search in a Rotated Sorted Array
Updated
Problem statement
You are given an integer array nums with distinct values. It was sorted in strictly increasing order, then rotated by moving a prefix to the end. A rotation by zero positions is allowed.
For example, [1,2,3,4,5,6] can become [5,6,1,2,3,4].
Return the zero-based index of target, or -1 if it is absent. Return -1 for an empty array. Find an O(log(n + 1))-time solution.
Function
searchRotated(nums: int[], target: int) → intExamples
Example 1
nums = [5,6,1,2,3,4]target = 2return = 3The value 2 occurs at index 3 in the rotated array.
Example 2
nums = [5,6,1,2,3,4]target = 7return = -1The array contains no value equal to 7.
Example 3
nums = []target = 0return = -1The empty array has no target index.
Constraints
0 <= nums.length <= 100000-10^9 <= nums[i] <= 10^9-10^9 <= target <= 10^9- All values in
numsare distinct. numsis a rotation of a strictly increasing array.
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Sliding Window MaximumPHONE SCREEN · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
- Koko Eating BananasThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Find First and Last Position in a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Longest Increasing SubsequenceAngel One · PHONE SCREEN
- Aggressive CowsAmazon · PHONE SCREEN
- Find First and Last Position of Element in Sorted ArrayEPAM · PHONE SCREENEPAM interview questions
- Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
- Search in Rotated Sorted ArrayZoomInfo · PHONE SCREEN
- Find a Peak ElementFox Corporation · PHONE SCREEN