📉

Index of Minimum in Sorted Rotated Array

Intermediate

Given a rotated sorted array, find the index of the minimum element using binary search.

15-20 min
Level 1 - Easy

Index of Minimum in Sorted Rotated Array

Enter the index of the minimum element in the rotated sorted array below.

Array:

[3,4,5,1,2]

Enter Index of Minimum Element:

Pseudocode


function findMinIndex(arr):
    left = 0
    right = arr.length - 1
    while left < right:
        mid = (left + right) // 2
        if arr[mid] < arr[right]:
            right = mid
        else:
            left = mid + 1
    return left
Progress1 / 4
Algorithm:Index of Minimum in Sorted Rotated Array
🎯 How to Play

1. Study the array shown on the left

2. Enter the index of the minimum element

3. Click "Check Solution" to verify

4. Use Tab to move between fields

5. Click "Next Level" to try more

🔄 Algorithm Steps

Step 1: Use binary search to compare mid and right

Step 2: If arr[mid] < arr[right], minimum is in left half (including mid)

Step 3: Otherwise, minimum is in right half (excluding mid)

Step 4: When left == right, you have found the minimum index

📊 Level Info

Difficulty: Easy

Array Size: 5

📖 Algorithm Explanation

Algorithm Explanation

The goal is to find the index of the minimum element in a rotated sorted array. The array was originally sorted in ascending order, but then rotated at some pivot. All elements are unique.

  • Initialize left to 0 and right to the last index.
  • While left is less than right:
    • Find mid as the floor of (left + right) / 2.
    • If arr[mid] < arr[right], the minimum is in the left half (including mid), so set right = mid.
    • Otherwise, the minimum is in the right half (excluding mid), so set left = mid + 1.
  • When the loop ends, left will be the index of the minimum element.

This approach runs in O(log n) time, making it efficient for large arrays.