Your question is Linux Path Simplification. 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.
Meta's Linux-based production hosts receive paths from command-line tooling that may contain redundant separators and directory references. Implement a function that returns the canonical form of an absolute Linux path.
Resolve the path using these rules:
/ characters act as one separator.. component means the current directory and should be removed... component moves to the parent directory. If the path is already at /, remain at /./ and must not end with /, unless the result is the root path /.Given a string path containing an absolute Linux path, return a string containing its canonical absolute path. Directory names do not contain /; names such as ... or file.. are ordinary directory names.
//, ., and .. componentsdef simplify_path(path):