Minimum Array Value Within an Inclusive Value Range
Company: Capital One
Role: Machine Learning Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Online Assessment
Overview: An easy array problem from a machine learning engineer online assessment: given positive integers and an inclusive value range, return the smallest element whose value falls inside the range, or 0 when none does. It tests careful reading of range semantics, inclusive bounds and a sentinel return value.
Read the full Capital One Machine Learning Engineer interview experience this question came from
Constraints
- 1 <= len(nums) <= 10^5
- 1 <= nums[i] <= 10^9
- 1 <= low <= high <= 10^9
Examples
Input: ([8, 3, 15, 6, 11], 5, 12)
Expected Output: 6
Explanation: Source Example 1: 8, 6 and 11 lie in [5, 12]; the smallest of them is 6.
Input: ([1, 2, 20], 5, 10)
Expected Output: 0
Explanation: Source Example 2: elements sit on both sides of [5, 10] but none inside, so the answer is 0.
Hints
- Both ends of the range are inclusive: an element equal to low or to high counts.
- The range filters element values, not positions, and the smallest element of the whole array may fall outside it.
- Every element is at least 1, so 0 can safely stand for the case where nothing qualifies.