Leetcode Problem 2227. Encrypt and Decrypt Strings

2227. Encrypt and Decrypt Strings

Leetcode Solutions

HashMap and Trie-based Encryption and Decryption

  1. Initialize two HashMaps (encryptMap and decryptMap) and a Trie (trieRoot).
  2. Populate encryptMap with keys as keys and values as values.
  3. Populate decryptMap with values as keys and sets of corresponding keys as values.
  4. Encrypt each word in dictionary and add it to the Trie.
  5. For encryption, iterate over each character in word1, look up the encrypted value in encryptMap, and concatenate the results.
  6. For decryption, recursively check every possible character mapping for each pair of characters in word2 against the Trie, and count the number of valid strings that match words in the dictionary.
UML Thumbnail

HashMap-based Encryption and Decryption

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...