FastPrepLowest Number in an Open Range
Problem · Array

Lowest Number in an Open Range

Learn this problem
EasyTiktok logoTiktokINTERNOA
See Tiktok hiring insights

Problem 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[]) → int

Examples

Example 1

numbers = [11,4,23,9,10]nRange = [5,12]return = 9

The 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 = 0

No 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 = 3

The qualifying values are 3, 3, and 5. The smallest is 3.

Constraints

  • 1 ≤ numbers.length ≤ 100
  • 1 ≤ numbers[i] ≤ 100
  • nRange.length = 2
  • Both values in nRange are positive integers that fit in a signed 32-bit integer.
  • nRange[0] ≤ nRange[1]

More Tiktok problems

drafts saved locally
public int findLowestInRange(int[] numbers, int[] nRange) {
    // Write your code here.
}
numbers[11,4,23,9,10]
nRange[5,12]
expected9
checking account