DescriptionQ283
Q283ArchASIC interview problem
Find the densest 4 KiB page
TechniquesAssociative arrayAddress alignmentHistogram
DifficultyEasy
TopicMemory Systems
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
Given an associative array keyed by written addresses, return the 4 KiB-aligned page base containing the most keys and its density.

Function headerSystemVerilog
function automatic void densest_page_4kb(
input bit [31:0] mem[longint unsigned],
output longint unsigned densest_page,
output int unsigned density
);Example input and output
Use this case to check your interpretationInput
written addresses=[0x1004,0x1010,0x1FFC,0x2000]Output
page_base=0x1000; density=3Explanation
The first three keys share page number 1 after shifting by 12; the fourth belongs to page 0x2000.
02
Requirements (4)
- Count keys by shifting each address right by 12.
- Return the page base, not the page number.
- Return zero outputs for an empty input.
- Break equal-density ties in favor of the lower page base.
