Return Every Matching Decryption
Problem statement
Build an encrypter from unique one-character keys, their two-character values, and a plaintext dictionary. Different keys may map to the same encrypted value.
Process every row [method, word] in operations:
encrypt: map each character ofword. If any character is unmapped, the encryption is the empty string.decrypt: return every dictionary occurrence whose full encryption equalsword, rather than returning a count.
The result contains one row per operation. An encrypt row contains exactly its one encryption string. A decrypt row contains matching dictionary strings in their original dictionary order; repeated dictionary occurrences are retained. If none match, that row is empty.
Function
processEncrypterMatches(keys: String[], values: String[], dictionary: String[], operations: String[][]) → String[][]Examples
Example 1
keys = ["a","b","c","d"]values = ["ei","zf","ei","am"]dictionary = ["abcd","acbd","adbc","badc","dacb","cadb","cbda","abad"]operations = [["encrypt","abcd"],["decrypt","eizfeiam"]]return = [["eizfeiam"],["abcd","abad"]]The encryption is unchanged from the base exercise. Decrypt now returns the two matching plaintext strings themselves, in dictionary order.
Example 2
keys = ["a","b"]values = ["xy","xy"]dictionary = ["a","b","a"]operations = [["decrypt","xy"],["encrypt","c"]]return = [["a","b","a"],[""]]All three dictionary occurrences match xy. Encrypting an unmapped character returns the empty string.
Constraints
1 <= keys.length == values.length <= 26.- Every key is a distinct lowercase English character represented as a one-character string.
- Every value contains exactly two lowercase English characters; values need not be unique.
1 <= dictionary.length <= 100; repeated dictionary strings are allowed.1 <= operations.length <= 100.- An
encryptword has length at most2000. - A
decryptword has positive even length at most200.