Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Find the two largest distinct values

Hardware interview practice

Find the two largest distinct values

EasyArraysSystemVerilog

Return the largest and second-largest distinct integers in an array.

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 = [9, 1, 9, 7, 4]
Expected output
largest = 9, second_largest = 7

The duplicate 9 does not count as a second distinct value.

What to cover

Requirements

  1. Assume at least two distinct values exist.
  2. Use one pass.
  3. Handle negative values.
asic.fyi · Learn silicon end to end.info@asic.fyi