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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
    • Datatype and Bit Puzzles
    • Fork Join Puzzles
    • Queue and Array Puzzles
      • Queue Mutation Plus Dynamic Resize
      • Queue Assignment Copies by Value
      • Pop from Empty Queue
      • Dynamic Array Resize with Class Handles
      • Associative Array Iteration Order
      • Locator Methods Return New Queues
    • String and Casting Puzzles
    • SystemVerilog Language Puzzles: Tricky Q&A
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹Queue and Array Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. SystemVerilog Language Puzzles
  4. Queue and Array Puzzles
  5. Queue Mutation Plus Dynamic Resize

VLSI DV Interview Puzzles · All levels

Queue Mutation Plus Dynamic Resize

Compute final `q`, `deleted`, and `da` after all operations.

On this page

    Puzzle

    Difficulty: Easy · Puzzle 1 of 6 · Topic: Queue and Array Puzzles

    Compute final `q`, `deleted`, and `da` after all operations.

    Code

    p1.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    module p1;
      int q[$] = '{1,2,3};
      int da[] = '{10,20,30,40};
      int deleted;
      initial begin
        q.push_front(9);        // {9,1,2,3}
        q.insert(2, 77);        // {9,1,77,2,3}
        deleted = q.pop_back(); // deleted=3, q={9,1,77,2}
        q.delete(1);            // {9,77,2}
    
        da = new[2](da);        // {10,20}
        da = new[5](da);        // {10,20,0,0,0}
        $display("q=%p deleted=%0d da=%p", q, deleted, da);
      end
    endmodule

    Hint

    Queue methods mutate immediately; dynamic-array `new[N](old)` copies only prefix `min(old.size, N)`.

    Step-by-step solution

    Diagram
    1) Queue operations produce `{9,77,2}` and popped value 3.
    2) Resizing to 2 truncates dynamic array to first two elements.
    3) Resizing to 5 extends that truncated array and default-initializes new slots to 0.

    Answer

    Answer: q=' {9,77,2}, deleted=3, da=' {10,20,0,0,0}

    Why candidates get it wrong

    People expect second resize to recover old truncated elements, but they are already lost.

    Interviewer follow-up

    How can you preserve full original data before truncating a dynamic array?

    Related topics

    • Back to Queue and Array Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    17 / 210

    Next: Queue Assignment Copies by Value

    Up next

    Up nextQueue Assignment Copies by Value

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Pop from Empty Queue
    • Dynamic Array Resize with Class Handles
    • Associative Array Iteration Order