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).
Be the first one to answer
Add answer anonymously...
Top ShareChat SDE-2 interview questions & answers
Popular interview questions of SDE-2
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app