Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ020
Page ↗
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 interpretation
Input
values = [1, 2, 2, 2, 5], target = 2
Output
lower_bound = 1, upper_bound = 4
Explanation

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.