Normalize an absolute path
Normalize an absolute POSIX path string using slash separators, dot and dot-dot. Going above root stays at root; repeated slashes collapse. Do not access the filesystem.
parts = ['a', 'b']
parts.pop() # process ..
print('/'+'/'.join(parts))Reason about the state
Push ordinary components on a stack, ignore dots and pop for dot-dot when possible. This is a lexical transformation, so symbolic links are outside the contract. Before writing code, identify what each variable means after one iteration. Walk through the example and explain why the next transition preserves that meaning. Then check the smallest permitted input and a case with repeated values. A correct answer follows the contract for every input, including the boundary cases in the checks. Keep any input mutation within the stated rules; return a fresh result when the task asks for one.
Your task
Normalize an absolute POSIX path string using slash separators, dot and dot-dot. Going above root stays at root; repeated slashes collapse. Do not access the filesystem.
The explanation opens here once every check passes.