Encrypt and Decrypt Strings
Canonical source (LeetCode 2227, Encrypt and Decrypt Strings). You are given a character bijection and a dictionary, and you must support encryption and count valid dictionary decryptions.
keys[i]is a character andvalues[i]is a two-character string. Encrypting a charactercreplaces it withvalues[i]wherekeys[i] == c. Encrypting a string encrypts each character in order.dictionaryis a list of permitted words.decrypt(word2)returns how many strings indictionaryencrypt toword2. Multiple dictionary words may encrypt to the same ciphertext (decryption multiplicity), so decryption counts must reflect that multiplicity.- The
Encrypterclass lifecycle is: construct with(keys, values, dictionary), callencrypt(word1)for any word, and calldecrypt(word2)to obtain the count of dictionary words whose encryption equalsword2.
Platform execution ABI blocker (shared, read-only). The established execution schema for this slug is functional: solve(arg1: string[]) -> number, with read-only fixtures shaped as [string[]] -> number (count of distinct non-empty strings). This ABI cannot represent the constructor/encrypt/decrypt operation sequence, the keys/values mapping, or ciphertext-to-dictionary multiplicity required by LC2227. Central ABI/transport/fixture/schema changes are required for true LC2227 lifecycle coverage. Solutions and starters in this repository must remain schema/entry-point-aligned to the established solve contract for central verification; the content below documents the canonical semantics and the blocker explicitly.
Established contract example (current ABI)
Input: arg1 = ["cat", "", "cat", "dog"]
Output: 2
Explanation: Under the established functional contract, the distinct non-empty strings are "cat" and "dog".
- Canonical LC2227:
1 <= keys.length == values.length <= 26,values[i].length == 2,1 <= dictionary.length <= 100,1 <= dictionary[i].length <= 100, all strings consist of lowercase English letters,keysandvaluesform a valid bijection mapping in context. - Established platform ABI:
arg1is an array of strings; return a number as defined by read-only fixtures.
Related Problems
- implement-trie-prefix-tree
Companies Asked
- Amazon
- Microsoft
- Meta
Encrypt and Decrypt Strings
**Canonical source (LeetCode 2227, Encrypt and Decrypt Strings).** You are given a character bijection and a dictionary, and you must support encryption and count valid dictionary decryptions.