Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
    • Constraint Solving Order Puzzles
      • Implication vs Partitioned Branches
      • Bidirectional Solving of x+y==10
      • if-else with Overlap on One Value
      • randc Cycle with a Skipped Value
      • Width Wrap in a Sum Constraint
      • Array Size Coupled to Content
    • Distribution Puzzles (`dist`, `:=` vs `:/`)
    • solve...before Bias Puzzles
    • randomize() with Puzzles
    • Randomization & Constraint Puzzles: Tricky Q&A
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Constraint Solving Order Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. Randomization & Constraint Puzzles
  4. Constraint Solving Order Puzzles
  5. Array Size Coupled to Content
On this page

    VLSI DV Interview PuzzlesAll levels

    Array Size Coupled to Content

    Compute P(len==4) for BOTH classes under tuple counting. Then compare size_sorted with the same class when the data elements are free in {0,1} (baseline 4/7): why does the ordering constraint reduce the bias toward long arrays?

    Puzzle

    Difficulty: Medium · Puzzle 6 of 6 · Topic: Constraint Solving Order Puzzles

    Compute P(len==4) for BOTH classes under tuple counting. Then compare size_sorted with the same class when the data elements are free in {0,1} (baseline 4/7): why does the ordering constraint reduce the bias toward long arrays?

    Code

    design.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    class size_content;
      rand int unsigned len;
      rand byte data[];
      constraint c {
        len inside {[2:4]};
        data.size() == len;
        foreach (data[i]) data[i] == i;
      }
    endclass
    
    class size_sorted;
      rand int unsigned len;
      rand byte data[];
      constraint c {
        len inside {[2:4]};
        data.size() == len;
        foreach (data[i]) data[i] inside {[0:1]};
        foreach (data[i]) if (i > 0) data[i] >= data[i-1];
      }
    endclass

    Hint

    For each legal len, count the data arrays that satisfy the foreach constraints, then sum over len.

    Step-by-step solution

    Diagram
    1) size_content: len in 2..4, and foreach pins data to {0..len-1}. One array per len: 3 tuples, P(len==4)=1/3.
    2) size_sorted: data is a non-decreasing 0/1 sequence of length len, i.e. some zeros followed by some ones. There are len+1 such sequences for each len.
    3) Tuples: len=2 -> 3, len=3 -> 4, len=4 -> 5, total 12.
    4) P(len==4)=5/12 (~41.67%), P(len==2)=3/12=1/4, P(len==3)=1/3. That is more likely than a uniform length (1/3) but less likely than free elements.
    5) Without the ordering constraint each len would have 2**len arrays (4+8+16=28 tuples) and P(len==4)=16/28=4/7.

    Answer

    Answer: size_content: P(len==4)=1/3 (one array per len). size_sorted: 12 tuples, P(len==4)=5/12. Size and content are solved jointly, and the content constraints decide how many tuples each size owns.

    How this was checked

    Checked by running a model of the rule in a Python model. Exact enumeration of the constraint set per the LRM (the LRM defines the distribution; simulator solvers need not be uniform). Verilator returned an empty array for this size+foreach shape, so the tuple counts come from enumerating (len, data[]) pairs here.

    Why candidates get it wrong

    Assuming longer arrays automatically get more solutions only holds if elements are free (2**len, giving 4/7 for len 4). Pinning the elements gives exactly 1 per len, and the ordering constraint gives only len+1 per len, so the bias towards long arrays shrinks from 4/7 to 5/12. Read it against the right baseline: 5/12 is more likely than a uniform length (1/3) but less likely than free elements (4/7). (Verilator 5.048 returned an empty array for this size+foreach shape, so the counts come from exact enumeration, not from execution.)

    Interviewer follow-up

    How would allowing data[i] inside {[0:1]} with no ordering change len bias? Model answer: each len owns 2**len arrays: 4 + 8 + 16 = 28 tuples, so P(len==2)=4/28=1/7, P(len==3)=8/28=2/7 and P(len==4)=16/28=4/7. The bias towards long arrays becomes strong.

    Say it out loud

    In size_content, foreach pins the data for each length, so there is one array per length, three tuples, and the chance of length four is one third. In size_sorted the data is a non-decreasing zero-one sequence, so length two has three arrays, length three has four and length four has five, twelve in total, and the chance of length four is five twelfths. The trap is assuming longer arrays always own more solutions; that is only true with free elements, where it would be four sevenths. Next I would check the baseline I am comparing against.

    Related topics

    • Constraining Array Size

    • foreach Constraints

    • Back to Constraint Solving Order Puzzles

    • Randomization & Constraint Puzzles section

    Previous

    91 / 293

    Next: Distribution Puzzles (`dist`, `:=` vs `:/`)

    Up next

    Up nextDistribution Puzzles (`dist`, `:=` vs `:/`)

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Implication vs Partitioned Branches
    • Bidirectional Solving of x+y==10
    • if-else with Overlap on One Value