I have a list of paths
[]string{"/a/path/to/something", "/a/path/in/something", "/a/path/in/something/else"}
I'd like to remove the Longest Common prefix from all paths so that the remaining part of it is the distinct part of the path.
For the above example the result should be
[]string{"to/something", "in/something", "in/something/else"}
My attempt so far has been fairly brute force so far:
Split up all paths by "/"
map["/a/path/to/something": [a path to something], "": [a path in something], "/a/path/in/something/else": [a path in something else]}
Pick any entry of the map and use that as a reference
- Iterate over the single elements of that picked entry and check the others on that position if they match
- If a non matching element is found the sequence is broken; take the remaining path of each path from
path[len(iterated_elem_so_far):]
Is there a more sophisticated way of accomplishing this?