Problem
Submissions

Problem: Find Minimum in Rotated Sorted Array II

Statement

Imagine you have an array, nums, of length nn that was originally sorted in non-decreasing (ascending) order. This array has been rotated between 11 and nn times. For example, the sorted array [0,2,3,3,5,7,11][0,2,3,3,5,7,11] can become:

  • [5,7,11,0,2,3,3][5,7,11,0,2,3,3], if rotated 33 times

  • [0,2,3,3,5,7,11][0,2,3,3,5,7,11], if rotated 77 times

A single rotation moves the last element to the front. So, if the original array is [a[0],a[1],...,a[n−1]][a[0], a[1], ..., a[n-1]], rotating it once produces [a[n−1],a[0],a[1],...,a[n−2]][a[n-1], a[0], a[1], ..., a[n-2]].

You are given a sorted, rotated array, nums, that may include duplicate elements. Your job is to return the minimum element in the array.

Try to solve this problem with the fewest possible operations.

Constraints:

  • n==n == nums.length

  • 1≤n≤10001 \leq n \leq 1000

  • −1000≤-1000 \leq nums[i] ≤1000\leq 1000

  • nums is sorted and rotated between 11 and nn times.

Problem
Submissions

Problem: Find Minimum in Rotated Sorted Array II

Statement

Imagine you have an array, nums, of length nn that was originally sorted in non-decreasing (ascending) order. This array has been rotated between 11 and nn times. For example, the sorted array [0,2,3,3,5,7,11][0,2,3,3,5,7,11] can become:

  • [5,7,11,0,2,3,3][5,7,11,0,2,3,3], if rotated 33 times

  • [0,2,3,3,5,7,11][0,2,3,3,5,7,11], if rotated 77 times

A single rotation moves the last element to the front. So, if the original array is [a[0],a[1],...,a[n−1]][a[0], a[1], ..., a[n-1]], rotating it once produces [a[n−1],a[0],a[1],...,a[n−2]][a[n-1], a[0], a[1], ..., a[n-2]].

You are given a sorted, rotated array, nums, that may include duplicate elements. Your job is to return the minimum element in the array.

Try to solve this problem with the fewest possible operations.

Constraints:

  • n==n == nums.length

  • 1≤n≤10001 \leq n \leq 1000

  • −1000≤-1000 \leq nums[i] ≤1000\leq 1000

  • nums is sorted and rotated between 11 and nn times.