Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Trivial Directory Path Function

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

Your question is Trivial Directory Path Function. 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

OpenAI Codex may receive a current workspace directory and a user-provided location. Implement a function that resolves the location into a normalized absolute POSIX path without accessing the filesystem.

If new_location is absolute, resolve it from the root and ignore current_dir. Otherwise, resolve it relative to current_dir. A . component has no effect, and a .. component moves to the parent directory. Attempts to move above / remain at /. Collapse repeated separators and remove trailing separators except for the root path.

Formal Specification

Given two non-empty strings, current_dir and new_location, return a string containing the normalized absolute path. current_dir is always absolute and uses / as the separator. Both paths contain only POSIX-style components, /, ., and ...

Constraints

  • current_dir is an absolute POSIX path.
  • new_location is non-empty.
  • Each input path has at most 10^4 characters.
  • Parent references cannot move above /.
  • No filesystem access is required.

Function Signature

def resolve_path(current_dir, new_location):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output