Reported April 2026
Duolingohash table

Encrypt and Decrypt Strings

Reported by candidates from Duolingo's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Duolingo OA. Under 2s to a working solution.
Founder's read

Duolingo reported this one in April 2026, and it looks like a design question but it's really a hash map question. You build an encrypter, then handle encrypt and decrypt operations in order. The trap is decrypt, because different keys can share the same two-character value, so you can't just reverse the mapping. If you're taking this OA in the next day or two, the whole problem comes down to what you precompute in the constructor. StealthCoder is there as a safety net on the live assessment if you blank, but the idea is short enough to hold in your head.

The problem

Build an encrypter from three constructor inputs:
keys[i] is a unique one-character key;
values[i] is the two-character encryption for that key; and
dictionary contains valid plaintext words.
Process each row [method, word] in operations:
encrypt: replace every character of word with its mapped two-character value. If any character has no key, the result is the empty string.
decrypt: count dictionary entries whose complete encryption equals word.
Return one string per operation in order. An encryption result is returned directly; a decryption count is returned in decimal form. Different keys may share the same encrypted value.

Function
processEncrypter(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","2"]
abcd encrypts to eizfeiam. Exactly abcd and abad in the dictionary produce that ciphertext.
Example 2
keys = ["a","b"]
values = ["aa","bb"]
dictionary = ["ab","ba"]
operations = [["encrypt","ac"],["decrypt","aabb"]]
return = ["","1"]
The first word contains an unmapped character. Only ab encrypts to aabb.

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, and dictionary words contain only lowercase English letters.
1 <= operations.length <= 100.
An encrypt word has length at most 2000.
A decrypt word has positive even length at most 200.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: don't decrypt by searching. Decrypt is ambiguous because one ciphertext chunk can map back to several keys, so brute-force reversal blows up. Flip it. In the constructor, encrypt every dictionary word once and store the results in a hash map from ciphertext to count. Then decrypt is a single lookup, returning 0 if the string is missing. Encrypt uses a map from key character to its two-character value. If any character is missing, return an empty string. The common pitfall is encrypting dictionary words lazily on every decrypt call, or forgetting that a dictionary word with an unmapped character never gets counted. Also remember the decrypt count goes back as a decimal string. Build the count map by looping each word, and skip words that fail to encrypt. If you freeze mid-OA, StealthCoder can surface this precompute-and-lookup structure so you aren't derailing on the ambiguity.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Encrypt and Decrypt Strings cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as encrypt and decrypt strings. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Duolingo's OA.

Duolingo reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Encrypt and Decrypt Strings FAQ

What's the trick in the Duolingo Encrypt and Decrypt Strings problem?+

Precompute. Encrypt every dictionary word once in setup and store ciphertext to count in a hash map. Decrypt then becomes one lookup. Trying to reverse the mapping fails because several keys can share one two-character value.

How hard is this problem really?+

Easy to medium. There's no fancy algorithm, just two hash maps and careful handling of edge cases. Most people who struggle try to decode the ciphertext directly instead of comparing against encrypted dictionary words.

What happens when a character has no key?+

Encrypt returns an empty string for the whole word. For the dictionary, a word containing an unmapped character can never match any ciphertext, so skip it when building the count map. Example 2 shows this with the word ac.

Why can't I just reverse the value-to-key mapping?+

Values aren't unique. In example 1, a and c both map to ei, so one chunk has multiple possible keys. Reversing creates branching you don't need. Comparing against precomputed dictionary encryptions avoids it entirely.

How do I prepare for this in 48 hours?+

Write it once from scratch. Build a char-to-string map, a ciphertext-to-count map, and a loop over operations that returns strings. Test both examples, including the empty string result and a count of 0 for a missing ciphertext.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Duolingo.

OA at Duolingo?
Invisible during screen share
Get it