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
Build a File Management App
00:00
5 left

Build a File Management App

MediumPython

Problem

Tell me about your experience building a file management app.

For the hands-on portion, implement recursive directory-size aggregation from a list of absolute file paths and sizes. Given files, return a mapping from every directory, including /, to the total size of files it contains directly or through descendants. Example: [["/docs/a.txt", 10], ["/docs/sub/b.txt", 5]] returns { "/": 15, "/docs": 15, "/docs/sub": 5 }; a root-level file contributes only to /.

Constraints

  • 1 <= files.length <= 1000
  • Each file entry is [path, size], where path and size are a string and non-negative integer
  • Paths are absolute, begin with /, and contain at least one file name
  • Paths do not have trailing slashes and contain no . or .. components
  • File paths are unique
  • Each path contains at most 100 directory components
  • Return every directory that is an ancestor of at least one file, plus /

Function Signature

def directory_sizes(files):
Interviewer

Your question is Build a File Management App. 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.