← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are a miner trying to build the next block for a blockchain. You have a pool of pending transactions, each with a byte size and an associated transaction fee. The block you are constructing has a hard byte-size limit (the “knapsack capacity”). Your goal is to select a subset of the transactions that fits inside this limit while maximizing the total fees you collect. Formally, you are given an integer capacity W and two integer arrays size[0 … n-1] and fee[0 … n-1]. You must return the maximum total fee that can be obtained by choosing a subset of indices such that the sum of the corresponding sizes is ≤ W. This is the classic 0/1 knapsack problem: each transaction can be either included once or not at all.