Shortest Completing Word Problem

Shortest Completing Word Problem — ExecCode Easy DSA Practice

Solve the Shortest Completing Word problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a string licensePlate and an array of strings words, find the shortest completing word in words. Your task is to compute the required answer and return the shortest completing word in words . A completing word is a word that contains all the letters in licensePlate. Ignore numbers and spaces in licensePlate, and treat letters as case insensitive. If a letter appears more than once in licensePlate, then it must appear in the word the same number of times or more. For example, if licensePlate= "aBc 12c", then it contains letters 'a', 'b' (ignoring case), and 'c' twice.

Examples

Input {"licensePlate": "1s3 PSt", "words": ["step", "steps", "stripe", "stepple"]}; Output steps. Input {"licensePlate": "1s3 456", "words": ["looks", "pest", "stew", "show"]}; Output pest

Constraints

1 <= licensePlate.length <= 7 licensePlate contains digits, letters (uppercase or lowercase), or space ' '. 1 <= words.length <= 1000 1 <= words[i].length <= 15 words[i] consists of lower case English letters.

Practice Shortest Completing Word free on ExecCode. Browse DSA problems, topic map, and placement guides.