FastPrepSearch in a Rotated Sorted Array with Duplicates
Problems/Search in a Rotated Sorted Array with Duplicates

Search in a Rotated Sorted Array with Duplicates

ByteDance logoByteDance● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names the search in a rotated array and says duplicate values are allowed. It does not say what to do with duplicates, and it gives no input limits. In our version, you return an index, and we chose the simplest fixed rules. Our version is about 90% the same as the reported question.

Given an integer array nums that was sorted in nondecreasing order and then rotated at an unknown pivot, return the lowest array index whose value equals target.

The array may contain duplicate values. If target does not occur, return -1.

Your algorithm should use the sorted, rotated structure to discard unambiguous regions. Because duplicate boundary values can hide the sorted side, the worst case may require examining every element.

Function

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

Examples

Example 1

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

The target occurs at indices 3 and 4, so the lowest matching index is 3.

Example 2

nums = [1,1,3,1]target = 3return = 2

The array is a rotation of a nondecreasing array and the only 3 is at index 2.

Example 3

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

The target does not occur, so the result is -1.

Constraints

  • 1 <= nums.length <= 100000.
  • -2147483648 <= nums[i], target <= 2147483647.
  • Before rotation, nums was sorted in nondecreasing order.
  • nums may contain duplicate values.
  • The array was rotated at an arbitrary pivot, including a rotation by zero positions.

More ByteDance Phone Screen questions

  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Implement QuicksortPHONE SCREEN · Seen Dec 2026
  • Largest Rectangle in HistogramPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Reverse Linked ListPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Count N-Queens PlacementsPHONE SCREEN · Seen Nov 2026
  • Matrix EscapePHONE SCREEN · Seen Nov 2026
  • Largest Number Below N from Reusable DigitsPHONE SCREEN · Seen Nov 2026
  • Log Analyzer: Busiest Service in a Rolling WindowPHONE SCREEN · Seen Nov 2026
  • Majority ElementPHONE SCREEN · Seen Nov 2026
  • Valid ParenthesesPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Single Element in a Sorted ArrayGreyOrange · PHONE SCREENGreyOrange interview questions
  • Count Winning Dice Face PairsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Search in a Rotated Sorted ArrayAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • 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
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Search a 2D MatrixWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • 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

ByteDance interview experiences

  • ByteDance TikTok USDS SWE Intern Interview: 1 Experience
  • ByteDance MLE New Grad Interviews: 1 Experience
  • ByteDance Security SRE Intern Phone Screens: 1 Experience
  • ByteDance USDS New Grad SWE Phone Screen: 1 Experience
  • ByteDance New Grad Data Engineer Video Interviews: 1 Experience
  • ByteDance Trust & Safety Research Scientist Intern: 1 Experience
All ByteDance interview questionsSee ByteDance hiring insights
Saved
class Solution {
    public int search(int[] nums, int target) {
      // write your code here
    }

}
Checking account…