All problems
Context Window Packing
Problem
Pack blocks of token counts into a context budget in order. The first block costs its size and every later block also pays a separator. Stop at the first block that does not fit rather than skipping it.
Return [count, used] for the packed prefix.
Hint
Track used tokens and only add the separator when a previous block is already packed.
Test cases
case 1
in: [[3,4,5],10,1]
expected: [2,8]
case 2
in: [[],10,1]
expected: [0,0]
case 3
in: [[5],10,1]
expected: [1,5]
case 4
in: [[6,6],10,1]
expected: [1,6]
case 5
in: [[4,4,4],10,2]
expected: [2,10]
Starter codePython
def context_packing(blocks, budget, separator):
# Your code here
pass5 test cases · run your code against them in the editor