Canonicalize OneDrive Sync Paths With Dot Segments
Last updated: November 29, 2026
Quick Overview
Given an absolute Unix-style path from the OneDrive sync client, return its canonical form by collapsing repeated slashes, removing "." segments and resolving ".." segments, never going above the root.
Microsoft
November 29, 20260
0
0 solved
Given an absolute Unix-style path from the OneDrive sync client, return its canonical form by collapsing repeated slashes, removing "." segments and resolving ".." segments, never going above the root.
Asked in Microsoft technical screens for client and storage teams, since a sync engine has to decide whether two differently spelled paths refer to the same file. The interviewer wants to see you pick a stack naturally and handle the root boundary without special-case clutter.
What the Interviewer Expects
- Tokenize on slashes and ignore empty tokens
- Use a stack of directory names
- Treat ".." at root as a no-op
- Treat names like "..." as ordinary directories
- Return "/" for an empty stack
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
- How would you handle a relative path plus a current working directory?
- How would symbolic links change the problem?
- How would you compare Windows paths, which are case-insensitive and use backslashes?
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 is an absolute path starting with /. Output starts with a single /, has single slashes between names, has no trailing slash (unless it is the root itself), contains no . or .. segments, ...
High-Level Design
A path is a sequence of moves through a tree: a name moves down, .. moves up, . stays put. A stack models the current location from the root, so each token is a push, a pop, or nothing. Splitting ...