Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Find lower and upper bounds

Hardware interview practice

Find lower and upper bounds

MediumArraysSystemVerilog

For a sorted integer array, return the first index with value >= target and the first index with value > target.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
values = [1, 2, 2, 2, 5], target = 2
Expected output
lower_bound = 1, upper_bound = 4

The half-open matching range [1,4) contains all three occurrences of 2.

What to cover

Requirements

  1. Return values.size() when the requested bound does not exist.
  2. Handle duplicate targets correctly.
  3. Use half-open search intervals.
Continue practicing

Related questions

Firmware AlgorithmsFind a calibration insertion position→
asic.fyi · Learn silicon end to end.info@asic.fyi