FastPrepSpelling Bee Word Filter

Spelling Bee Word Filter

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

You are given an array of unique lowercase words dictionary, a one-character string required, and a six-character string optional.

Return every dictionary word that satisfies all of these rules:

  • The word contains at least four letters.
  • The required letter appears at least once.
  • Every character is either the required letter or one of the optional letters.
  • Allowed letters may be repeated any number of times.

Preserve the words' original dictionary order.

Function

spellingBeeWords(dictionary: String[], required: String, optional: String) → String[]

Examples

Example 1

dictionary = ["encode","nonce","done","node","oven","deed","coded","envy","no"]required = "n"optional = "vcodey"return = ["encode","nonce","done","node","oven","envy"]

deed and coded omit the required letter, while no is too short.

Example 2

dictionary = ["pole","tone","toll","gone","trope","ton","google","people","noon","longer"]required = "o"optional = "gleptn"return = ["pole","tone","toll","gone","google","people","noon"]

ton is shorter than four letters. trope and longer contain the disallowed letter r.

Example 3

dictionary = []required = "a"optional = "bcdefg"return = []

An empty dictionary has no matching words.

Constraints

  • 0 <= dictionary.length <= 100000.
  • Every dictionary word is unique, nonempty, and contains only lowercase English letters.
  • The total number of characters across dictionary is at most 1000000.
  • required contains exactly one lowercase English letter.
  • optional contains exactly six distinct lowercase English letters, none equal to required.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] spellingBeeWords(String[] dictionary, String required, String optional) {
    // Write your code here.
}
dictionary["encode","nonce","done","node","oven","deed","coded","envy","no"]
required"n"
optional"vcodey"
expected["encode", "nonce", "done", "node", "oven", "envy"]
Checking account…