Smallest and Largest in a Rotated Sorted Array
Updated
Problem statement
An array of different integers was put in increasing order and then rotated: its first k elements, for some k with 0 <= k < n, were moved in the same order to the end. For example, rotating [6,13,29,44,58,71] with k = 3 gives [44,58,71,6,13,29]. With k = 0 the array stays sorted.
You are given the rotated array nums, but not k. Return a list of two numbers: the smallest value in nums, then the largest value.
Function
minAndMax(nums: int[]) → int[]Examples
Example 1
nums = [44,58,71,6,13,29]return = [6,71]The sorted array [6,13,29,44,58,71] was rotated so that it starts at 44. The smallest value, 6, sits at index 3, and the largest, 71, sits right before it at index 2.
Example 2
nums = [-8,-2,5,11]return = [-8,11]The array was not rotated at all, so the smallest value is the first element and the largest is the last.
Example 3
nums = [9,-4]return = [-4,9]Two values with the drop between them: the smallest is -4 (index 1) and the largest is 9 (index 0).
Constraints
1 <= nums.length <= 5000-10^9 <= nums[i] <= 10^9- All values in
numsare different, andnumsis an increasing array rotated by somekwith0 <= k < nums.length
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
- Koko Eating BananasThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Find First and Last Position in a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
- Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Longest Increasing SubsequenceAngel One · PHONE SCREEN
- Aggressive CowsAmazon · PHONE SCREEN
- Find First and Last Position of Element in Sorted ArrayEPAM · PHONE SCREENEPAM interview questions
- Find K Closest Elements in a Sorted ArrayNavi · PHONE SCREEN
- Search in Rotated Sorted ArrayZoomInfo · PHONE SCREEN
- Find a Peak ElementFox Corporation · PHONE SCREEN
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)