Skip to the selected question
ASIC.FYI

ASIC Interview Question Bank

1,000+ hardware interview questions.Curated and reviewed by industry engineers.1,000+ hardware questions1,000+ questionsEngineer-reviewed
DescriptionQ284
Page ↗
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.

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.
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 interpretation
Input
page densities={0x1000:3,0x2000:1,0x3000:3,0x4000:2}; K=3
Output
[(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.