Practice Encrypt and Decrypt Strings
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Encrypter(keys,values,dictionary) maps each distinct key character to a two-letter string; values may repeat. encrypt(word1) concatenates mappings, returning an empty string if a character has no mapping. decrypt(word2) counts distinct dictionary words whose encryption equals word2. It does not count all theoretically possible plaintext strings. Practice approach: Build the character map and pre-encrypt every dictionary word that can be encoded. Count identical ciphertexts in a frequency map, making decryption a lookup. This avoids exponential branching when several keys share a code. Test code collisions and dictionary entries containing unmapped characters.
Source: Encrypt and Decrypt Strings on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["Encrypter","encrypt","decrypt","decrypt"] [[["a","b","c"],["xy","zz","xy"],["ab","cb","aa","d"]],["ab"],["xyzz"],["zzxy"]]
[null,"xyzz",2,0]
ab and cb both encrypt to xyzz. No dictionary entry encrypts to zzxy; d cannot be encoded.
Constraints
Related LeetCode Problems
Practice more problems similar to Encrypt and Decrypt Strings.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.