Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Find Rotation Count

Easy Acceptance 75% Points 20

Given a rotated sorted array of distinct integers, return the number of times the array has been rotated. The rotation count is equal to the index of the minimum element in the array. The array was originally sorted in ascending order and then rotated clockwise.

Examples
Example 1

Example 1

Input: nums = [15,18,2,3,6,12]

Output: 2

Explanation: The minimum element is 2, which is at index 2. Therefore, the array has been rotated 2 times.

Example 2

Example 2

Input: nums = [7,9,11,12,5]

Output: 4

Explanation: The minimum element is 5 at index 4, so the array has been rotated 4 times.

Example 3

Example 3

Input: nums = [1,2,3,4,5]

Output: 0

Explanation: The array is not rotated. The minimum element is at index 0, so rotation count is 0.

Constraints
  • 1 = nums.length = 105
  • -104 = nums[i] = 104
  • All values in nums are distinct
Topics
Binary Search
Companies
Apple
Added 19 Jul 2026 75% acceptance
Ln 1, Col 1Sign in to save your code
3 4 5 1 2
3