FastPrepExact String Matching

Exact String Matching

WhatNot logoWhatNot● MediumINTERNPHONE SCREEN
Learn

Problem statement

Given an array of strings dictionary and an array of strings queries, return one boolean for each query in the same order.

A query matches if it is exactly equal to at least one complete string in dictionary. Matching a prefix or substring alone is not sufficient.

  • Duplicate dictionary strings do not change the result.
  • The empty string is an ordinary string: it matches only if an empty string appears in dictionary.
  • Return an empty boolean array when there are no queries.

Function

matchStrings(dictionary: String[], queries: String[]) → boolean[]

Examples

Example 1

dictionary = ["cat","car","dog"]queries = ["cat","ca","cart","dog"]return = [true,false,false,true]

Only complete dictionary strings match. A prefix or a longer extension does not match.

Example 2

dictionary = ["","a","a"]queries = ["","a","aa"]return = [true,true,false]

The empty string is present, and duplicate dictionary entries do not change membership.

Example 3

dictionary = []queries = ["x",""]return = [false,false]

An empty dictionary contains no strings, including the empty string.

Constraints

  • 0 <= dictionary.length <= 500 and 0 <= queries.length <= 500.
  • Each string contains only lowercase English letters and has length from 0 to 40.
  • The total length of dictionary strings is at most 5000; the total length of queries is at most 5000.

More WhatNot problems

See WhatNot hiring insights
public boolean[] matchStrings(String[] dictionary, String[] queries) {
    // write your code here
}
dictionary["cat","car","dog"]
queries["cat","ca","cart","dog"]
expected[true,false,false,true]
Checking account…