FastPrepEncrypt and Decrypt Strings
Problems/Encrypt and Decrypt Strings

Encrypt and Decrypt Strings

Duolingo logoDuolingo● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source specifies the Encrypter constructor and both methods. This practice version uses a finite operation list and stringifies decrypt counts only to provide one language-neutral return type.

You are building an encrypter. It is set up from three inputs:

  • keys[i] is a one-character key. No two keys are the same.
  • values[i] is the two-character value that replaces that key.
  • dictionary lists the valid plain words.

Then go through each row [method, word] in operations:

  • encrypt: replace every character of word with its two-character value. If any character has no key, the result is the empty string.
  • decrypt: count how many dictionary words encrypt to exactly word.

Return one string per operation, in order. For an encrypt, return the encrypted string. For a decrypt, return the count written in digits. Different keys may share the same 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"]

The keys map a to ei, b to zf, c to ei and d to am. So abcd encrypts to eizfeiam. For the decrypt, only abcd and abad in the dictionary encrypt to eizfeiam, so the count is two.

Example 2

keys = ["a","b"]values = ["aa","bb"]dictionary = ["ab","ba"]operations = [["encrypt","ac"],["decrypt","aabb"]]return = ["","1"]

In ac, the character c has no key, so the encrypt result is the empty string. For the decrypt, only ab encrypts to aabb, so the count is one.

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.

More Duolingo Phone Screen questions

  • Group Timestamps into Consecutive-Day IntervalsPHONE SCREEN · Seen Nov 2026
  • Return Every Matching DecryptionPHONE 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
  • 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
  • In-Memory Vault File SystemHarvey · 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[] processEncrypter(String[] keys, String[] values, String[] dictionary, String[][] operations) {
        // write your code here
    }
}
Checking account…