Example 1
Arguments: [
[
7,
2
],
4,
[
0,
3,
4,
7
]
]
Expected result: [
28,
31,
8,
11
]Positions 0 and 3 map inside physical page 7; positions 4 and 7 map inside page 2.
KV memory and quantization · Easy
Problem 32 of 50 · Python and NumPy
Translate logical token positions into physical storage slots using a sequence block table. For position p, logical page = p//block_size, offset = p%block_size, physical slot = block_table[logical_page]*block_size+offset. Return slots in the same order as token_positions; repeated or unsorted positions are allowed.
def page_addresses(block_table, block_size, token_positions):Arguments: [
[
7,
2
],
4,
[
0,
3,
4,
7
]
]
Expected result: [
28,
31,
8,
11
]Positions 0 and 3 map inside physical page 7; positions 4 and 7 map inside page 2.
Arguments: [
[
3,
1
],
2,
[
3,
0,
3
]
]
Expected result: [
3,
6,
3
]Position 3 maps to slot 3, position 0 to slot 6; duplicate lookups remain duplicated.