Question
Implement the path-resolution part of a shell `cd` command. ```python def cd(cwd: str, dest: str) -> str: ... ``` ## Requirements - `cwd` is an absolute normalized path. - An absolute `dest` starts from `/`; a relative destination starts from `cwd`. - Ignore empty components and `.`. - `..` removes one component but never moves above `/`. - Collapse repeated slashes, remove trailing slashes except for root, and keep `/` as `/`. - Treat names literally; filesystem existence and permissions are outside the first stage. Examples should cover root, nested parents, absolute destinations, repeated separators, and names containing dots that are not exactly `.` or `..`. ## Follow-ups 1. Expand `~` and environment variables with explicit security rules. 2. Resolve symbolic links and explain logical versus physical `..` semantics. 3. Consult a filesystem interface for missing paths and permissions. 4. Explain why changing directory must be implemented by the shell process.