← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE coding round, one question the whole time, a path simplification problem that sounds straightforward until you factor in relative paths against a working directory context. Felt like a LeetCode medium dressed up with extra edge cases.

Questions Asked (1)

Q1

Given a Unix-style path string (which may be absolute or relative) and a current working directory, return the canonical absolute path. Handle dots, double-dots, consecutive slashes, trailing slashes, and edge cases from resolving relative paths against the given working directory.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I went straight to stack-based simplification like I always do for path problems, but the relative path piece tripped me up initially.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem constraints and edge cases first, then propose a stack-based solution that processes the path component by component. Walk through examples to demonstrate handling of dots, double-dots, and slashes, and discuss time/space complexity.

Pro tip: Mention that you can avoid explicit string splitting by using two pointers to parse components on the fly, which reduces memory overhead and shows attention to performance.

1. Clarify requirements and edge cases

Ask about input format, expected output, and specific edge cases like empty path, root path, and paths with only dots. Confirm whether the working directory is always absolute.

2. Choose data structures and algorithm

Decide to use a stack (or list) to store canonical path components. Explain that you'll process the path from left to right, handling each component based on its value.

3. Handle absolute vs relative paths

If the path is absolute, start with an empty stack; if relative, initialize the stack with the components of the working directory. This ensures correct resolution.

4. Process each component

Iterate through the path, splitting by slashes. For each component: ignore empty or '.'; for '..', pop from stack if not empty; otherwise, push the component onto the stack.

5. Construct and return canonical path

Join the stack components with '/' and prepend '/' for absolute paths. Handle the root case (empty stack) by returning '/'.

Key Points to Mention

  • Time and space complexity: O(n) time and O(n) space, where n is the length of the path.
  • Edge cases: empty path, path with only slashes, path with trailing slash, path with multiple consecutive slashes, path with '..' at root (should stay at root).
  • Handling of relative paths: resolve against the given working directory, which itself should be canonicalized first.
  • Use of a stack to efficiently handle '..' by popping the last component.
  • Avoiding unnecessary string operations by processing components in a single pass.
  • Testing with examples: e.g., path='/a/./b/../../c/', cwd='/home/user' -> '/home/c'.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.