Minimum of a Valley Array
Updated
Problem statement
You are given an integer array nums shaped like a valley. Its values strictly go down until they reach a lowest point, and after that they strictly go up.
Either part may be empty. So the whole array may only go up (the lowest point is the first value), or only go down (the lowest point is the last value). Two values on different sides of the lowest point may be equal, but two neighbors are never equal.
Return the smallest value in nums. Try to do it in O(log n) time, where n is the length of nums.
Function
valleyMinimum(nums: int[]) → intExamples
Example 1
nums = [9,4,2,5,8]return = 2The values go down from 9 to 4 to 2, then go up to 5 and 8. The lowest point is 2.
Example 2
nums = [3,6,10]return = 3The going-down part is empty: the values only go up. So the first value, 3, is the smallest.
Example 3
nums = [12,8,5,1,-3]return = -3The going-up part is empty: the values only go down. So the last value, -3, is the smallest.
Constraints
1 <= nums.length <= 10000-10^9 <= nums[i] <= 10^9- There is an index
kwithnums[0] > nums[1] > ... > nums[k]andnums[k] < nums[k + 1] < ... < nums[nums.length - 1].
More Bloomberg LP Onsite Interview questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Roll a Weighted DieLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Implement Binary SearchQualys · ONSITE INTERVIEWQualys interview questions
- Messages in an Inclusive Timestamp RangeAttentive · PHONE SCREEN · ONSITE INTERVIEWAttentive interview questions
- Count Occurrences in a Sorted ArrayAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
- Closest Version DateAmazon · ONSITE INTERVIEW
- Recursive Binary SearchEPAM · ONSITE INTERVIEWEPAM interview questions
- Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
- Find Maximum Frequency of NumberGoogle · ONSITE INTERVIEWGoogle interview questions
- Song Duration Pairs Divisible by 60The Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
- Search a Sorted Array of WordsExpedia · ONSITE INTERVIEWExpedia interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)