FastPrepDouble Substitution Decryption
Problems/Double Substitution Decryption

Double Substitution Decryption

Upstart logoUpstart● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report describes two learned substitution stages and asks you to decrypt through both while ignoring whitespace. It leaves out the mapping format and the whitespace rules. We added them, with limits, below. Our version is about 82% the same as the reported question.

A message was transformed by two one-to-one character substitutions:

  1. Alice's characters were substituted into Bob's characters.
  2. Bob's characters were substituted into Carol's characters.

You receive aligned clear/cipher training text for each stage:

  • alicePlain and bobCipher define the Alice-to-Bob mapping.
  • bobPlain and carolCipher define the Bob-to-Carol mapping.

When learning either mapping, remove all whitespace from both aligned strings before pairing their characters. The non-whitespace strings have equal lengths and consistently define one-to-one mappings.

Decrypt encryptedMessage from Carol's alphabet back to Bob's alphabet, then from Bob's alphabet back to Alice's alphabet. Preserve every whitespace character in encryptedMessage unchanged. Return the fully decrypted message.

Function

decryptDoubleSubstitution(alicePlain: String, bobCipher: String, bobPlain: String, carolCipher: String, encryptedMessage: String) → String

Examples

Example 1

alicePlain = "abc"bobCipher = "bcd"bobPlain = "bcd"carolCipher = "cde"encryptedMessage = "edc cde"return = "cba abc"

Reversing the Carol-to-Bob mapping changes edc cde to dcb bcd. Reversing the Bob-to-Alice mapping then produces cba abc.

Example 2

alicePlain = "a b c"bobCipher = "x y z"bobPlain = "x y z"carolCipher = "m n o"encryptedMessage = "mno onm"return = "abc cba"

Whitespace in the training text does not create mapping entries. The single space in the encrypted message is preserved.

Constraints

  • Each input string has length from 1 through 10^5.
  • After whitespace removal, each training pair has equal length.
  • Each training pair defines a consistent one-to-one mapping.
  • Every non-whitespace character needed while decrypting is covered by the corresponding inverse mapping.
  • Characters are case-sensitive.

More Upstart Online Assessment questions

  • Buffet Day GainsOA · Seen Sep 2026
  • Case-Insensitive Anagram CheckOA · Seen Sep 2026
  • Filter Duplicates While Preserving OrderOA · Seen Sep 2026
  • Scale Ingredient QuantitiesOA · Seen Sep 2026
  • ABO Parent Genotype CombinationsOA · Seen Aug 2026
  • Chunked Byte Stream ChecksumsOA · Seen Aug 2026
  • Cluster Size on DiskOA · Seen Aug 2026
  • Add Drama to Text GroupsOA · Seen Jul 2026
  • Lexicographic Word FrequenciesOA · Seen Jul 2026
  • Minimum Absolute Pair DifferenceOA · Seen Jul 2026

Similar questions at other companies

  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Perfect SubstringAXQ Capital · OA
  • Count Suffix Word PairsTikTok · OATikTok interview questions
  • Password Clues and the Next CommandOpenAI · OAOpenAI interview questions
  • Decode Words with Anagram KeysCresta · OACresta interview questions
  • Count One-Swap Number PairsCapital One · OACapital One interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
  • Longest Distinct StringSuperhuman · OASuperhuman interview questions
  • Longest String ChainVisa · OAVisa interview questions
All Upstart interview questionsSee Upstart hiring insights
Saved
class Solution {
    public String decryptDoubleSubstitution(String alicePlain, String bobCipher, String bobPlain, String carolCipher, String encryptedMessage) {
        // Write your code here.
    }
}
Checking account…