Code Room
CodingEasycod-g1037
Subject Networking route prefixLevel Entry–Mid~15 minCommon in Networking & APIs · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Given a list of URL paths, compute their longest common path prefix for routing purposes, matching on whole path segments (not characters). Each path starts with '/'. Return the common prefix as a path string starting with '/' (e.g. '/api/v1'); if the only common ancestor is the root, return '/'. An empty list returns '/'. A single path returns that path.

Implement
common_path_prefix(paths: list[str]) → str
Examples
in[["/api/v1/users","/api/v1/orders","/api/v1/users/5"]]out"/api/v1"
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.