PIXELBANKv8.2.1
Menu

Design Add and Search Words Data Structure

MediumTries

Design a data structure that supports adding words and searching with '.' wildcards (matches any letter).

Input: Line 1: comma-separated operations (add/search). Line 2: comma-separated arguments. Output: Result of each search operation, one per line.

Example:

Input:
add,add,search,search,search,search
bad,dad,.ad,b..,b.d,b..
Output:
True
True
True
True
Reasoning:
  • The data structure is initialized, and then two words are added: "bad" and "dad".
  • The first search operation is ".ad", which matches both "bad" and "dad", so it returns True.
  • The next three search operations are "b..", "b.d", and "b..", which match "bad" and/or "dad", so they all return True.
  • The results of the search operations are printed one per line, but since the first two operations are "add", only the last four operations (two "add" and two "search" that returned False are not shown, only the last two "search" that returned True are shown with the first two "search" that also returned True) are relevant to the output, resulting in the output: True, True, True, True, but only the last 4 values are shown, with the first two being "add" operations, so the first two True values are from the "search" operations.

Constraints:

  • 1 <= word.length <= 25
  • '.' matches any single letter
  • Words consist of lowercase English letters
Editor

Test Results

0/0
Run code to see test results.