FastPrepSearch in Rotated Sorted Array
Problems/Search in Rotated Sorted Array

Search in Rotated Sorted Array

Kotak Mahindra Bank logoKotak Mahindra Bank● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two reports name this same task and give the full goal. We chose the input limits and the function signature. Our version is about 99% the same as the reported questions.

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) → int

Examples

Example 1

nums = [4,5,6,7,0,1,2]target = 0return = 4

The target appears at index 4.

Example 2

nums = [4,5,6,7,0,1,2]target = 3return = -1

The target is absent.

Constraints

  • 1 <= nums.length <= 100000.
  • Every value in nums is distinct and in [-10^9, 10^9].
  • nums is a rotation of a strictly increasing array.
  • target is 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
All Kotak Mahindra Bank interview questionsSee Kotak Mahindra Bank hiring insights
Saved
class Solution {
    public int searchRotated(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…