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. Locator Methods Return New Queues

VLSI DV Interview Puzzles · All levels

Locator Methods Return New Queues

What are `evens`, `idx`, and final `q` after these locator operations?

On this page

    Puzzle

    Difficulty: Hard · Puzzle 6 of 6 · Topic: Queue and Array Puzzles

    What are `evens`, `idx`, and final `q` after these locator operations?

    Code

    p6.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    module p6;
      int q[$] = '{1,2,3,4,5,6};
      int evens[$];
      int idx[$];
      initial begin
        evens = q.find with (item % 2 == 0);
        idx = q.find_index with (item > 3);
        q = q.find with (item < 4);
        $display("evens=%p idx=%p q=%p", evens, idx, q);
      end
    endmodule

    Hint

    `find` returns matching values; `find_index` returns matching indices; both produce new queues.

    Step-by-step solution

    Diagram
    1) `find` over original q picks values 2,4,6 into `evens`.
    2) `find_index` over original q for `item > 3` yields indices 3,4,5.
    3) Final assignment `q = q.find(item < 4)` replaces q with `{1,2,3}`.

    Answer

    Answer: evens=' {2,4,6}, idx=' {3,4,5}, q=' {1,2,3}

    Why candidates get it wrong

    A common miss is assuming locator methods mutate the source queue in place.

    Interviewer follow-up

    How do results differ if you call `find_index` after reassigning `q`?

    Related topics

    • Back to Queue and Array Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    22 / 210

    Next: String and Casting Puzzles

    Up next

    Up nextString and Casting Puzzles

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Queue Mutation Plus Dynamic Resize
    • Queue Assignment Copies by Value
    • Pop from Empty Queue