Longest Common File-System Path Prefix
Problem statement
Every input is a canonical absolute Unix path: it starts with /, has no repeated separators, and has no trailing separator unless it is the root.
Return the longest path prefix whose complete components are shared by every input. Return / when no named component is common, and return an empty string when paths is empty.
Function
commonPathPrefix(paths: String[]) → StringExamples
Example 1
paths = ["/a/b/c","/a/b/d","/a/b"]return = "/a/b"Only complete common components are retained.
Example 2
paths = ["/alpha","/beta"]return = "/"Different first components share only the root.
Constraints
0 <= paths.length <= 10000- The total path length is at most
200000.