Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Build a File Management App

MediumPython00:00
Practice interviewer
In session
5 left
00:00

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

You need to log in / sign up to run or submit.

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):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output