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

Search in Rotated Sorted Array

Microsoft logoMicrosoft● MediumFULLTIMEINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report from a Microsoft Data Scientist Intern names a well-known problem. Our version follows the usual search in a rotated array of distinct values. We chose the function signature, the examples and the limits. Our version is about 99% the same as the reported question.

You are given an integer array nums that was originally sorted in strictly increasing order and then possibly rotated at an unknown pivot. All values in nums are distinct.

Given an integer target, return its index in nums. Return -1 when target is absent.

Your algorithm must run in O(log n) time.

Function

search(nums: int[], target: int) → int

Examples

Example 1

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

The value 0 appears at index 4.

Example 2

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

The value 3 does not appear in the array.

Example 3

nums = [1]target = 0return = -1

The one-element array contains 1, not 0.

Constraints

  • 1 <= nums.length <= 100000
  • -10^9 <= nums[i], target <= 10^9
  • All values in nums are distinct.
  • nums is a rotation of a strictly increasing array.

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum Number of Days to Make m BouquetsPhonePe · ONSITE INTERVIEWPhonePe interview questions
  • Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Search a Row- and Column-Sorted MatrixByteDance · ONSITE INTERVIEWByteDance interview questions
  • 3Sum SmallerSalesforce · ONSITE INTERVIEWSalesforce 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
  • Search in Rotated Sorted ArrayKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Find First and Last Position in Sorted ArrayPaytm · ONSITE INTERVIEWPaytm interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)
  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int search(int[] nums, int target) {
        // Write your code here.
    }
}
Checking account…