DescriptionQ020
Q020FWASIC interview problem
Find lower and upper bounds
TechniquesBinary searchSorted arrayDuplicates
DifficultyMedium
TopicArrays
LanguageSystemVerilog
Requirements3 checkpoints
01
Problem
For a sorted integer array, return the first index with value >= target and the first index with value > target.
Example input and output
Use this case to check your interpretationInput
values = [1, 2, 2, 2, 5], target = 2Output
lower_bound = 1, upper_bound = 4Explanation
The half-open matching range [1,4) contains all three occurrences of 2.
02
Requirements (3)
- Return values.size() when the requested bound does not exist.
- Handle duplicate targets correctly.
- Use half-open search intervals.
