FastPrepReturn Every Matching Decryption

Return Every Matching Decryption

Duolingo logoDuolingo● MediumFULLTIMEPHONE SCREEN
Learn

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 of word. If any character is unmapped, the encryption is the empty string.
  • decrypt: return every dictionary occurrence whose full encryption equals word, 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 encrypt word has length at most 2000.
  • A decrypt word has positive even length at most 200.

More Duolingo problems

See Duolingo hiring insights
public String[][] processEncrypterMatches(String[] keys, String[] values, String[] dictionary, String[][] operations) {
    // write your code here
}
keys["a","b","c","d"]
values["ei","zf","ei","am"]
dictionary["abcd","acbd","adbc","badc","dacb","cadb","cbda","abad"]
operations[["encrypt","abcd"],["decrypt","eizfeiam"]]
expected[["eizfeiam"], ["abcd", "abad"]]
Checking account…