Hardware interview practice
Constrain exactly one duplicated nonadjacent pair
Constrain ten integers so exactly one value occurs twice, the duplicate positions are nonadjacent, and every other value occurs once.
Starting point
Question code
rand int a[10];
rand int p, q;Reviewed example
Work through one case
Input
a = {7,1,2,7,3,4,5,6,8,9}, p = 0, q = 3Expected output
legal: exactly one repeated value (7) at nonadjacent positions 0 and 3Only value 7 repeats, its positions differ by three, and all remaining values are pairwise distinct.
What to cover
Requirements
- 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.
