Back to problems

Find Shortest Unique Prefix

Algorithm · Meta · Medium

Implement shortest_unique_prefixes(words). Given a list of strings words, return a list where each element is the shortest prefix of the corresponding input word that distinguishes that word from all other words in the list. The returned list must preserve the original input order. Example 1: Explanation: "zebra" is the only word starting with z, so "z" is enough. "dog" must be extended past the shared initial d to become unique. Likewise, "duck" is uniquely identified by…

Checking your access…