PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Meta

Implement cd and merge intervals

Last updated: Mar 29, 2026

Quick Overview

This question evaluates proficiency in filesystem path normalization (string parsing, tokenization, and edge-case handling) and interval-merging algorithms (sorting, range consolidation, and handling overlaps), testing skills in string manipulation, data structures, and algorithmic reasoning.

  • medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Implement cd and merge intervals

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem 1: Implement a simplified `cd` command You are given: - `cwd`: the current working directory as an absolute Unix path (starts with `/`). - `path`: a target path that may be absolute (starts with `/`) or relative. Implement the behavior of a simplified Linux `cd` command and return the resulting **normalized absolute path**. Normalization rules: - `.` means “stay in the same directory”. - `..` means “go to parent directory” (if already at `/`, stay at `/`). - Multiple consecutive slashes should be treated as a single separator. - The output must: - start with `/` - not end with `/` unless the path is exactly `/` **Input:** `cwd` (string), `path` (string) **Output:** normalized absolute path (string) **Examples** - `cwd = "/a/b"`, `path = "../c"` → `"/a/c"` - `cwd = "/"`, `path = "../../x"` → `"/x"` - `cwd = "/a/b"`, `path = "/d//e/./f/.."` → `"/d/e"` --- ## Problem 2: Merge overlapping intervals You are given a list of intervals `intervals`, where each interval is `[start, end]` (inclusive) and `start <= end`. Merge all intervals that overlap and return a list of the merged, non-overlapping intervals that cover the same ranges. Two intervals overlap if they share any point, i.e., `[a, b]` and `[c, d]` overlap when `c <= b`. **Input:** `intervals: List[List[int]]` **Output:** merged intervals (in any order, or sorted by start—specify which you choose) **Examples** - `[[1,3],[2,6],[8,10],[15,18]]` → `[[1,6],[8,10],[15,18]]` - `[[1,4],[4,5]]` → `[[1,5]]` **Constraints (typical):** - `1 <= len(intervals) <= 10^5` - interval endpoints fit in 32-bit integers

Quick Answer: This question evaluates proficiency in filesystem path normalization (string parsing, tokenization, and edge-case handling) and interval-merging algorithms (sorting, range consolidation, and handling overlaps), testing skills in string manipulation, data structures, and algorithmic reasoning.

Related Interview Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)
Meta logo
Meta
Jan 16, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
2
0
Loading...

Problem 1: Implement a simplified cd command

You are given:

  • cwd : the current working directory as an absolute Unix path (starts with / ).
  • path : a target path that may be absolute (starts with / ) or relative.

Implement the behavior of a simplified Linux cd command and return the resulting normalized absolute path.

Normalization rules:

  • . means “stay in the same directory”.
  • .. means “go to parent directory” (if already at / , stay at / ).
  • Multiple consecutive slashes should be treated as a single separator.
  • The output must:
    • start with /
    • not end with / unless the path is exactly /

Input: cwd (string), path (string)

Output: normalized absolute path (string)

Examples

  • cwd = "/a/b" , path = "../c" → "/a/c"
  • cwd = "/" , path = "../../x" → "/x"
  • cwd = "/a/b" , path = "/d//e/./f/.." → "/d/e"

Problem 2: Merge overlapping intervals

You are given a list of intervals intervals, where each interval is [start, end] (inclusive) and start <= end.

Merge all intervals that overlap and return a list of the merged, non-overlapping intervals that cover the same ranges.

Two intervals overlap if they share any point, i.e., [a, b] and [c, d] overlap when c <= b.

Input: intervals: List[List[int]]

Output: merged intervals (in any order, or sorted by start—specify which you choose)

Examples

  • [[1,3],[2,6],[8,10],[15,18]] → [[1,6],[8,10],[15,18]]
  • [[1,4],[4,5]] → [[1,5]]

Constraints (typical):

  • 1 <= len(intervals) <= 10^5
  • interval endpoints fit in 32-bit integers

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Meta•More Software Engineer•Meta Software Engineer•Meta Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.