Amazon Phone Interview SDE2

Q: Find the smallest number of register bits needed to store a set of N variables given their sizes.
The target architecture has R small (64 bit) registers and S larger (256 bit)
ones. Any register can hold multiple variables, but the large registers can be accessed only at 8-bit boundary.
A variable cannot be split into multiple registers.
// Example: N = 5, variables = {12, 64, 256, 32, 7}  bits long
// R=2, S=8   => 2 64bit registers  64, 12+32+7  into the 2x64b, and 256 into 1 256b
// Usage: 2 small, 1 large

Any idea on how to solve this?

Comments (3)