← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Went through a coding round at Meta for a software engineer role. Just the one problem but it had enough edge cases to keep me honest.

Questions Asked (1)

Q1

Given an absolute Unix-style path string, return its simplified canonical form.

Algorithms & Data Structures
Author's notes

I knew the stack approach pretty quickly, split on slashes, skip empty strings and dots, pop on double-dots, done.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to process the path components: split the path by '/', then iterate through each component. For each component, if it's '.' or empty, skip it; if it's '..', pop from the stack if not empty; otherwise, push the component. Finally, join the stack with '/' and prepend a '/' to form the canonical path.

Pro tip: Clarify edge cases upfront, such as multiple consecutive slashes, trailing slashes, and paths that reduce to root. Also, mention that you're handling the problem in O(n) time and O(n) space, which is optimal.

1. Understand the problem and edge cases

Restate the problem to ensure clarity. Identify edge cases like '/', '/../', '/home//foo/', and '/a/./b/../../c/'.

2. Choose the right data structure

Select a stack (or list) to keep track of valid directory names as you process the path components.

3. Process each component

Split the path by '/' and iterate. Skip empty strings and '.', pop for '..' if stack is not empty, otherwise push the directory name.

4. Construct the canonical path

Join the stack elements with '/' and ensure the result starts with a single '/'. If the stack is empty, return '/'.

5. Test with examples

Walk through provided examples and edge cases to verify correctness and discuss time/space complexity.

Key Points to Mention

  • Use of stack to handle '..' by popping the last directory
  • Splitting the path by '/' and filtering out empty strings and '.'
  • Handling of multiple consecutive slashes and trailing slashes
  • Time complexity O(n) and space complexity O(n)
  • Edge case where the path resolves to root ('/')
  • In-place modification is not possible due to string immutability, so extra space is needed

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