Hey kids, here's something to bake your noodle.
I have a full screen - say 800x480 at 16-bit color.
Therein, I have a 32kB window. This window allows me the memory to create up to a 128x128 bitmap at 16-bit color. Or 64x256. Or any rectangular region with that same area or less.
Creating rectangles using all available area is the ideal choice, but less area also works.
For a given screen, there are already rectangles of various sizes populating it at various locations, of various sizes, any area and potentially overlapping each other (but uncommon to do that). These rectangles must be filled around and otherwise untouched.
The goal is to fill the entire screen with as few rectangles as possible, each up to 32kB (128x128) in area.
I've come up with some code in the comments