Problem · Array
Lowest Number in an Open Range
Learn this problemProblem statement
You are given an array of positive integers numbers and a two-element array nRange describing a number range whose endpoints satisfy nRange[0] ≤ nRange[1].
Return the smallest value in numbers that lies strictly between the two endpoints. In other words, find the smallest numbers[i] such that nRange[0] < numbers[i] < nRange[1].
If no value satisfies both strict inequalities, return 0.
Function
findLowestInRange(numbers: int[], nRange: int[]) → intExamples
Example 1
numbers = [11,4,23,9,10]nRange = [5,12]return = 9The values strictly between 5 and 12 are 11, 9, and 10. Their minimum is 9.
Example 2
numbers = [1,3,2]nRange = [1,1]return = 0No integer can be strictly greater than 1 and strictly less than 1 at the same time, so the result is 0.
Example 3
numbers = [7,23,3,1,3,5,2]nRange = [2,7]return = 3The qualifying values are 3, 3, and 5. The smallest is 3.
Constraints
1 ≤ numbers.length ≤ 1001 ≤ numbers[i] ≤ 100nRange.length = 2- Both values in
nRangeare positive integers that fit in a signed 32-bit integer. nRange[0] ≤ nRange[1]