FastPrepReturn Every Matching Decryption
Problems/Return Every Matching Decryption

Return Every Matching Decryption

Duolingo logoDuolingo● MediumFULLTIMEINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two phone-screen reports describe this version of Encrypt and Decrypt Strings, where decrypt lists the matching words instead of counting them. The later intern report says the interviewer wanted them as a set. That report also says decrypt was meant to be a backtracking depth-first search that the candidate had to explain, and that the best approach was not required.

An earlier version of this problem allowed repeated dictionary words and repeated them in the answer. Neither report says that, and it does not fit a set. Here dictionary words are all different, as in the original problem, so each decrypt row is a set of words. We list each row in dictionary order, instead of the order a search finds the words, so that answers can be checked. When encrypt meets a letter that is not a key, it returns the empty string, as the original problem does. We chose the limits on keys, words and operations.

Our version is about 90% the same as the reported questions.

Build an encrypter from unique one-letter keys, their two-letter values, and a dictionary of distinct plaintext words. Different keys may have the same value.

Process every row [method, word] in operations:

  • encrypt: replace each letter of word with its value. If any letter is not a key, the result is the empty string.
  • decrypt: return the set of dictionary words whose encryption is exactly word, instead of how many there are.

Return one row per operation. An encrypt row holds exactly its one encrypted string. A decrypt row holds the matching dictionary words. So that the answer can be checked, list them in the order they appear in dictionary. If no word matches, the row is empty.

Interview Follow-up

In one interview, the interviewer did not ask for the fastest solution. They asked for decrypt to be written with depth-first search and backtracking: read word two letters at a time, try every key whose value equals the next two letters, and undo that choice before trying the next key. They also asked why depth-first search fits this problem and how the backtracking works.

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"]]

Encrypting abcd maps each letter to its value: ei, zf, ei, am. To decrypt eizfeiam, the blocks are ei, zf, ei, am. Block ei can come from a or c, so 2 * 1 * 2 * 1 = 4 plaintexts are possible: abad, abcd, cbad and cbcd. Only abcd and abad are in the dictionary, and they are listed in dictionary order.

Example 2

keys = ["a","b","c"]values = ["xy","xy","zz"]dictionary = ["ba","cab","ab","ca"]operations = [["decrypt","xyxy"],["decrypt","zzxy"],["encrypt","cad"]]return = [["ba","ab"],["ca"],[""]]

Keys a and b share the value xy, so xyxy could be aa, ab, ba or bb. The dictionary has ba and ab. They are listed as ba, then ab, because that is their order in the dictionary, even though a search that tries a before b finds ab first. zzxy can only be ca or cb, and only ca is in the dictionary. d is not a key, so encrypting cad gives the empty string.

Example 3

keys = ["m"]values = ["pq"]dictionary = ["mn","m"]operations = [["decrypt","pqpq"],["decrypt","pq"]]return = [[],["m"]]

pqpq could only be mm, which is not in the dictionary, so that row is empty. mn can never be decrypted, because n is not a key. pq decrypts to m.

Constraints

  • 1 <= keys.length == values.length <= 26. Every key is a different lowercase English letter.
  • Every value is exactly two lowercase English letters. Values do not have to be different.
  • 1 <= dictionary.length <= 100. Dictionary words are all different, and each has 1 to 100 lowercase English letters.
  • 1 <= operations.length <= 100. Each row is [method, word], where method is encrypt or decrypt.
  • An encrypt word has 1 to 2000 lowercase English letters. A decrypt word has an even number of lowercase English letters, from 2 to 200.

More Duolingo Phone Screen questions

  • Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
  • Visit Desired Attractions Without Reusing a TrailPHONE SCREEN · Seen Oct 2026
  • Correct an In-Place Array ReversalPHONE SCREEN · Seen Oct 2026
  • Count Starts Reaching a Grid MaximumPHONE SCREEN · Seen Oct 2026
  • Select the Top User MatchesPHONE SCREEN · Seen Oct 2026
  • Sum All Values in a Binary TreePHONE SCREEN · Seen Oct 2026
  • User Resource Transition ProbabilitiesPHONE SCREEN · Seen Oct 2026
  • Encrypt and Decrypt StringsPHONE SCREEN · Seen Apr 2026
  • Validate a Mahjong Hand PartitionPHONE SCREEN · Seen Nov 2025
  • Directional Tiles: Find a Valid Reconfiguration PathPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
  • Reference-Counted Deduplicating File SystemCitadel · PHONE SCREENCitadel interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • String Copy and Move LifecycleSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
  • Design In-Memory File SystemSnowflake · PHONE SCREENSnowflake interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Account Scheduler - Availability and AcquireStripe · ONSITE INTERVIEWStripe interview questions

Interview reports that mention this question

  • Duolingo SWE Interview Questions: 3 Experiences

Duolingo interview experiences

  • Duolingo interviews · November 2026
All Duolingo interview questionsSee Duolingo hiring insights
Saved
class Solution {
    public String[][] processEncrypterMatches(String[] keys, String[] values, String[] dictionary, String[][] operations) {
        // write your code here
    }
}
Checking account…