Skip to question
ASIC.FYI
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
ASIC.FYI/Interview questions/Return the top K densest pages

Q284·Free·SystemVerilog

Return the top K densest pages

Difficulty
Medium
Topic
Memory Systems
Language
SV
Interview prompt

Question

Return at most K individual 4 KiB pages ordered from highest to lowest density.

Page-density records entering a descending ordering stage with blank top-K result slots
Density is the primary key and lower page base is the deterministic tie-breaker.
Starting point

Question code

function automatic void densest_top_k_page_4kb(
  input bit [31:0] mem[longint unsigned],
  input int unsigned k,
  output longint unsigned pages[$],
  output int unsigned densities[$]
);
Reviewed example

Trace one case

Input
page densities={0x1000:3,0x2000:1,0x3000:3,0x4000:2}; K=3
Expected output
[(0x1000,3),(0x3000,3),(0x4000,2)]

Density sorts descending and the lower page base wins the tie between the two density-three pages.

What to cover

Requirements

  1. Return min(K, number of populated pages) records.
  2. Order by density descending.
  3. Break equal-density ties by lower page base.
  4. Clear output queues before appending.
Exact question handoffPractice Q284

Solve it in the question bank, keep your progress, and reveal the reviewed solution when your access allows.

Open in question bank →
Solution accessA Free account unlocks the complete reviewed solution.
Continue learning

SystemVerilog

  • Memory Systems
  • Top K
  • Sorting
  • Histogram
Interview preparation guide →
Continue practicing

Related questions

Q283 · Memory SystemsFind the densest 4 KiB page→Q256 · Memory SystemsReturn every page at the kth density rank→Q242 · Memory SystemsEstimate the densest page in a bounded stream→
ASIC.FYI · Learn silicon end to end.info@asic.fyi