Tap here to switch tabs
Problem
Submissions

Problem: Shortest Completing Word

med
30 min
Try to solve the Shortest Completing Word problem.

Statement

Given a string licensePlate and an array of strings words, find the shortest completing word in words.

A completing word is a word that contains all the letters in licensePlate, ignoring case. Characters in licensePlate that are not letters (such as digits and spaces) are ignored. If a letter appears multiple times in licensePlate, it must occur at least that many times in the completing word.

Return the shortest completing word. If there are multiple shortest completing words with the same minimum length, return the first one that appears in words.

Constraints:

  • 1≤1 \leq licensePlate.length ≤7\leq 7

  • licensePlate contains digits, letters (uppercase or lowercase), or space ' '.

  • 1≤1 \leq words.length ≤1000\leq 1000

  • 1≤1 \leq words[i].length ≤15\leq 15

  • words[i] consists of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shortest Completing Word

med
30 min
Try to solve the Shortest Completing Word problem.

Statement

Given a string licensePlate and an array of strings words, find the shortest completing word in words.

A completing word is a word that contains all the letters in licensePlate, ignoring case. Characters in licensePlate that are not letters (such as digits and spaces) are ignored. If a letter appears multiple times in licensePlate, it must occur at least that many times in the completing word.

Return the shortest completing word. If there are multiple shortest completing words with the same minimum length, return the first one that appears in words.

Constraints:

  • 1≤1 \leq licensePlate.length ≤7\leq 7

  • licensePlate contains digits, letters (uppercase or lowercase), or space ' '.

  • 1≤1 \leq words.length ≤1000\leq 1000

  • 1≤1 \leq words[i].length ≤15\leq 15

  • words[i] consists of lowercase English letters.