Service name shorthand
An internal deploy CLI lets an engineer type a shortened service name instead of the whole thing. A shorthand is any leading piece of a name, from its first character up to the entire name, and the CLI accepts a shorthand only when no other registered service starts with those same characters. You get names, the registered services in registration order. Return one shorthand per service in that same order: the shortest leading piece of that name which no other name in the list starts with. When every leading piece of a name, the whole name included, also starts some other service, that name cannot be shortened at all, so return the full name for it. Names are non empty, distinct and case sensitive. Return an empty list when names is empty.
shortest_unique_handles(names: list[str]) → list[str][["api","api-gateway","billing"]]out["api","api-","b"][["checkout","chat","cron"]]out["che","cha","cr"][["ab","abc"]]out["ab","abc"]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.
[["api","api-gateway","billing"]]["api","api-","b"]not run yetsample[["checkout","chat","cron"]]["che","cha","cr"]not run yetsample[["ab","abc"]]["ab","abc"]not run yetsample