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).

AnswerBot
4mo
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
Help your peers!
Add answer anonymously...
ShareChat SDE-2 interview questions & answers
A SDE-2 was asked Q. Given a non-negative integer x, compute and return the square root of x.
A SDE-2 was asked Q. Suppose an array of length n sorted in ascending order is rotated between 1 and ...read more
A SDE-2 was asked 9mo agoQ. Why ViewModel is necessary, how does it save state
Popular interview questions of SDE-2
A SDE-2 was asked Q1. Given a non-negative integer x, compute and return the square root of x.
A SDE-2 was asked Q2. Suppose an array of length n sorted in ascending order is rotated between 1 and ...read more
A SDE-2 was asked 9mo agoQ3. Why ViewModel is necessary, how does it save state
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

