Skip to content

Instantly share code, notes, and snippets.

@AlanD20
Created June 10, 2022 12:25
Show Gist options
  • Save AlanD20/43ec9a6f5b79cb56ccd4960686f48f11 to your computer and use it in GitHub Desktop.
Save AlanD20/43ec9a6f5b79cb56ccd4960686f48f11 to your computer and use it in GitHub Desktop.
Coding Problems

Algorithm Problem - Dictionary Lookup

  1. You have setup() function that accepts an array of words.
  2. Calling isInDict(word) function by passing a single string word. Returns true if it includes in the dictionary which we have initialized from setup() function.
  3. The word we pass it to isInDict() function, may have wild cards which each wild card represent a single letter.

Here is an example:

Dictionary initializatoin:

setup(['cat', 'car', 'bat', 'bald'])

Dictionary Loopup:

isInDict('cat')  // true
isInDict('care') // false
isInDict('*at')  // true, matches cat
isInDict('*a*')  // true, matches, cat, car, bat

Result:

  • The time complexity of your solution must be O(1).
  • case-sensitivity is up to the coder.

Tips:

  • You may use classes to persist the state of given dictionary.
  • You may use key/value pairs for better performance.
  • Remember you have setup() function to store the dictionary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment