Your question is Optimizing Mobile Image Loading. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The Ally Financial mobile app must load several images for a screen, such as account illustrations or promotional content. Given image priorities, sizes, cached images, and a maximum number of concurrent downloads, determine the order in which images finish loading when downloads are scheduled greedily.
An image with a higher priority must be selected before a lower-priority image whenever a download slot becomes available. If priorities are equal, select the smaller image first. If both priority and size are equal, select the lexicographically smaller id. Cached images require no download and must be excluded.
Implement image_load_order(images, cached_ids, max_concurrent). images is a list of dictionaries containing a unique string id, a positive integer size_kb, and an integer priority. cached_ids is a list of image IDs already stored locally. max_concurrent is the positive number of simultaneous downloads. Return a list of image IDs in completion order. If multiple images finish at the same time, return them in lexicographic ID order.
Assume download duration is proportional to size_kb, so an image of 500 KB takes 500 time units. All uncached downloads are available at time zero.
def image_load_order(images, cached_ids, max_concurrent):