Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ487
Q487DVASIC interview problem

Constrain exactly one duplicated nonadjacent pair

TechniquesSystemVerilogRelational constraintsExact duplicates
DifficultyHard
TopicConstraints
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Constrain ten integers so exactly one value occurs twice, the duplicate positions are nonadjacent, and every other value occurs once.

Starting declarationSystemVerilog
rand int a[10];
rand int p, q;

Example input and output

Use this case to check your interpretation
Input
a = {7,1,2,7,3,4,5,6,8,9}, p = 0, q = 3
Output
legal: exactly one repeated value (7) at nonadjacent positions 0 and 3
Explanation

Only value 7 repeats, its positions differ by three, and all remaining values are pairwise distinct.

02

Requirements (4)

  • Constrain 0 <= p < q < 10 and q - p > 1.
  • Require a[p] == a[q].
  • Require every other index pair to differ.
  • Bound all ten values to the inclusive range 0 through 99.