Deepest shared path

Write codeMedium15 min

Your task

Two services report their working directories as absolute Unix-style paths (they start with '/' and contain segments separated by single slashes, e.g. '/home/dev/app'). Return the deepest path both share, comparing whole segments, '/x/y' and '/x/yy' share only '/x', not '/x/y'. Return '/' when nothing beyond the root is shared. For example, '/home/dev/app/logs' and '/home/dev/api' share '/home/dev'.

Examples

common_path(a: str, b: str) -> str
Example 1
Inputcommon_path("/home/dev/app/logs", "/home/dev/api")
Output"/home/dev"