DescriptionQ284
Q284ArchFollow-up to Q283ASIC interview problem
Return the top K densest pages
TechniquesTop KSortingHistogram
DifficultyMedium
TopicMemory Systems
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Return at most K individual 4 KiB pages ordered from highest to lowest density.

Function headerSystemVerilog
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[$]
);Example input and output
Use this case to check your interpretationInput
page densities={0x1000:3,0x2000:1,0x3000:3,0x4000:2}; K=3Output
[(0x1000,3),(0x3000,3),(0x4000,2)]Explanation
Density sorts descending and the lower page base wins the tie between the two density-three pages.
02
Requirements (4)
- Return min(K, number of populated pages) records.
- Order by density descending.
- Break equal-density ties by lower page base.
- Clear output queues before appending.
