Find Minimum in Rotated Sorted Array
You are presented with a sorted array that has been rotated an unknown number of times. The nature of this rotation is such that each element shifts to the right with the last element moving to the front, as demonstrated with the sequence 1 2 3 4 becoming 4 1 2 3 after one such rotation. Your task is to identify the smallest number within this array.
Input:
The first line consists of the integer 'T', indicating the number of test cases.
For each test case, the first line provides the integer 'N', representing the array's size.
The subsequent line contains 'N' space-separated integers denoting the array elements.
Output:
For each test case, output the smallest element found in the array.
Provide each test case result on a new line.
Example:
Input:
2
5
4 5 6 7 0
4
3 4 0 1
Output:
0
0
Constraints:
1 <= T <= 10^2
1 <= N <= 10^4
1 <= ARR[i] <= 10^9
Note: Each element in the array is distinct.
Follow-Up: Aim to achieve this with a time complexity no greater than O(log(N)) and space complexity of O(1).
Find the smallest element in a rotated sorted array.
Use binary search to find the pivot point where rotation occurs.
Compare the element at the pivot point to determine the smallest element.
Handle case...read more
Top ShareChat SDE-2 interview questions & answers
Popular interview questions of SDE-2
Reviews
Interviews
Salaries
Users/Month