Normalize a Cloud Storage Object Path With Dot Segments
Last updated: November 29, 2026
Quick Overview
Given an absolute, Unix-style path for an object in a storage browser, return its canonical form by collapsing repeated slashes, removing single-dot segments, resolving double-dot segments against their parent, and never climbing above the root.
0
0
0 solved
Given an absolute, Unix-style path for an object in a storage browser, return its canonical form by collapsing repeated slashes, removing single-dot segments, resolving double-dot segments against their parent, and never climbing above the root.
A Google phone screen staple, framed here around a Cloud Storage console that must canonicalize user-typed paths before permission checks. Beyond the stack, the interviewer listens for why normalization matters for security (path traversal) and which segments are not special.
What the Interviewer Expects
- Splits on slashes and ignores empty and single-dot segments
- Uses a stack and pops on double dot, staying at root when empty
- Treats names like ... or .hidden as ordinary segments
- Returns / for a path that resolves to root
- Connects normalization to path traversal checks
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Support relative paths resolved against a current working directory.
- Symlinks exist; why can lexical normalization give the wrong answer, and what would you do?
- Normalize URL paths where segments can be percent-encoded, such as %2e%2e.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: an absolute path such as
/a/./b/../../c/. - Output: the canonical path: starts with one
/, no trailing slash (unless it is just/), no.or..segments, single slashes. ..at th...
High-Level Design
Split on /. Empty pieces come from repeated or trailing slashes, and . means "here", so both are skipped. A .. pops the last real segment if there is one. Every other piece is pushed. Joining th...