Search in Rotated Sorted Array
Updated
Problem statement
You are given an integer array nums containing distinct values. It was sorted in increasing order and then rotated at an unknown pivot.
Return the index of target if it appears in nums; otherwise return -1. Your algorithm must run in O(log n) time.
Function
searchRotated(nums: int[], target: int) → intExamples
Example 1
nums = [4,5,6,7,0,1,2]target = 0return = 4The target appears at index 4.
Example 2
nums = [4,5,6,7,0,1,2]target = 3return = -1The target is absent.
Constraints
1 <= nums.length <= 100000.- Every value in
numsis distinct and in[-10^9, 10^9]. numsis a rotation of a strictly increasing array.targetis in[-10^9, 10^9].
Source note: Author-written prompt excerpt retained for source fidelity.
More Kotak Mahindra Bank Onsite Interview questions
- Longest Common PrefixPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Nov 2026
- Maximum Non-Adjacent Coins in Two RowsONSITE INTERVIEW · Seen Oct 2026
- Find the Index of the First Occurrence in a StringONSITE INTERVIEW · Seen Oct 2026
- Roman to IntegerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Subarrays Whose Sum Is a Power of TwoONSITE INTERVIEW · Seen Oct 2026
- Remove Duplicates From Sorted Array In PlacePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Course ScheduleONSITE INTERVIEW · Seen Sep 2026
- House Robber IIONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
- First and Last Target Position in a Mountain ArrayGoogle · ONSITE INTERVIEWGoogle interview questions
- 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Smallest Batch Size Within a Step LimitMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Peak of an Increasing-Then-Decreasing ArraySnap Inc. · ONSITE INTERVIEWSnap Inc. interview questions
- Online Meeting Scheduler with Fixed RoomsUber · ONSITE INTERVIEWUber interview questions
- Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Find First and Last Position in Sorted ArrayPaytm · ONSITE INTERVIEWPaytm interview questions
- Detect a Silent SensorConfluent · ONSITE INTERVIEWConfluent interview questions