6 kyu

Urban Dictionary

1,537 of 2,178joh_pot

Description:

Design a data structure that supports the following two operations:

  • addWord / add_word which adds a word,
  • search which searches a literal word or a regular expression string containing lowercase letters "a-z" or "." where "." can represent any letter. Return true if the search term fully matches any word previously added; otherwise, return false.

You may assume that all given words contain only lowercase letters.

Examples

addWord("bad")
addWord("dad")
addWord("mad")

search("pad") === false
search("bad") === true
search(".ad") === true
search("b..") === true
wd = WordDictionary()

wd.add_word("bad")
wd.add_word("dad")
wd.add_word("mad")

wd.search("pad") == False
wd.search("bad") == True
wd.search(".ad") == True
wd.search("b..") == True
wd = WordDictionary.new

wd.add_word("bad")
wd.add_word("dad")
wd.add_word("mad")

wd.search("pad") == false
wd.search("bad") == true
wd.search(".ad") == true
wd.search("b..") == true

Note: the data structure will be initialized multiple times during the tests!

Algorithms
Object-oriented Programming

Stats:

CreatedOct 29, 2015
PublishedOct 29, 2015
Warriors Trained4139
Total Skips57
Total Code Submissions10980
Total Times Completed2178
JavaScript Completions1537
Python Completions582
Ruby Completions96
Total Stars86
% of votes with a positive feedback rating90% of 255
Total "Very Satisfied" Votes214
Total "Somewhat Satisfied" Votes30
Total "Not Satisfied" Votes11
Ad
Contributors
  • joh_pot Avatar
  • g964 Avatar
  • GiacomoSorbi Avatar
  • natan Avatar
  • anter69 Avatar
  • user9644768 Avatar
  • StephanieCunnane Avatar
  • Just4FunCoder Avatar
Ad