Code RoomPath prefix routing
EasyPrep Room Coding #198

Path prefix routing

CodingNetworking & APIsAlgorithms & data structuresEntry–Mid~15 min

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.

0:00 of about 15 min
InputExpectedGot
[["/api/v1/users","/api/v1/orders","/api/v1/users/5"]]"/api/v1"not run yetsample