Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Optimizing Mobile Image Loading
00:00
5 left

Optimizing Mobile Image Loading

HardPython

Problem

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.

Formal Specification

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.

Constraints

  • 1 <= len(images) <= 10^5
  • 1 <= max_concurrent <= len(images)
  • 1 <= size_kb <= 10^9
  • 0 <= priority <= 10^9
  • Image IDs are unique strings

Function Signature

def image_load_order(images, cached_ids, max_concurrent):
Interviewer

Your question is Optimizing Mobile Image Loading. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.