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 and values[i] is a two-character string. Encrypting a character c replaces it with values[i] where keys[i] == c. Encrypting a string encrypts each character in order.
  • dictionary is a list of permitted words. decrypt(word2) returns how many strings in dictionary encrypt to word2. Multiple dictionary words may encrypt to the same ciphertext (decryption multiplicity), so decryption counts must reflect that multiplicity.
  • The Encrypter class lifecycle is: construct with (keys, values, dictionary), call encrypt(word1) for any word, and call decrypt(word2) to obtain the count of dictionary words whose encryption equals word2.

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, keys and values form a valid bijection mapping in context.
  • Established platform ABI: arg1 is an array of strings; return a number as defined by read-only fixtures.

Related Problems

  • implement-trie-prefix-tree

Companies Asked

  • Google
  • Amazon
  • Microsoft
  • Meta
  • Twitter
Examples
Input: ["a","b"]
Output: 2
Hints

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.