← All problems

Simplify Path (Unix)

Medium stacksstrings LeetCode ↗
Given an absolute Unix-style path, canonicalize it: resolve '.' and '..' components, collapse multiple slashes, and return the simplified canonical path. For example, '/a/./b/../../c/' becomes '/c'.

Hints (0/3 revealed)

Log in to reveal hints progressively.

Complexity

Time O(n), Space O(n)

Common pitfalls

  • Popping on '..' past root
  • Keeping trailing slash

Your solution

Log in to save your code and track progress.