All practice tasks

Coding (Algo)

Normalize a Virtual Path

Stack · Easy

A virtual-file browser receives absolute paths with repeated separators and relative navigation segments. It needs a stable display path. This is lexical normalization only: no filesystem access or symlink resolution is involved.

Return the canonical absolute path after resolving empty segments, dot segments and parent navigation.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

A JSON object { "path": string }.

Fields

  • path is an ASCII string beginning with /. Segment names other than exactly . or .. are ordinary names.

Output

Return value

  • Ignore empty and . segments. .. removes the most recent normal segment if one exists; it cannot go above root.
  • Use one / between names and no final slash except at root.
  • Preserve ordinary segment names exactly, including ... and case.

Constraints

  • 1 <= path.length <= 100000. No filesystem or network calls.
  • Percent-decoding, permissions, links and security access checks are outside this lexical task.

Examples

Example 1

{
  "path": "/a//b/.././c/"
}

Returns

"/a/c"

b is removed by its following parent segment.

Example 2

{
  "path": "/../../x"
}

Returns

"/x"

Parent segments at root do nothing.

Required complexity

O(path.length) time and space

What this task practices

Normalize a Virtual Path is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.