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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Start free
Implement a Basic File System Interface
00:00
5 left

Implement a Basic File System Interface

HardPython

Problem

Implement a basic file system interface in Python.

Implement execute_file_system(operations), which processes an array of operation objects against an initially empty file system containing only the root directory /. Supported operations are mkdir, add_file, ls, and read. mkdir creates a directory, add_file creates or replaces a file, ls returns sorted immediate child names, and read returns file contents. All paths are absolute and valid; directory parents exist before their children are created. Return an array containing results only for ls and read operations, in operation order.

Constraints

  • 1 <= operations.length <= 10^4
  • Each path is absolute, valid, and contains no duplicate separators
  • All directory parents exist before a directory or file is created
  • A file path is never used as a directory path
  • Path depth is at most 100
  • File contents contain at most 10^4 characters
  • Directory listing results must be sorted lexicographically

Function Signature

def execute_file_system(operations):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
CodePython 3
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.