Decode the Message

You are given the strings key and message, which represent a cipher key and a secret message, respectively. The steps to decode message are as follows:

  • Use the first appearance of all 26 lowercase English letters in key as the order of the substitution table.
  • Align the substitution table with the regular English alphabet.
  • Each letter in message is then substituted using the table.
  • Spaces ' ' are transformed to themselves.

Return the decoded message.

Example 1
Inputkey = "the quick brown fox jumps over the lazy dog", message = "vkbs bs t suepuv"
Output"this is a secret"
The substitution table is obtained by taking the first appearance of each letter in key, which decodes the message to this is a secret.
Example 2
Inputkey = "eljuxhpwnyrdgtqkviszcfmabo", message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"
Output"the five boxing wizards jump quickly"
The substitution table is obtained by taking the first appearance of each letter in key, which decodes the message to the five boxing wizards jump quickly.

Constraints

  • 26 <= key.length <= 2000
  • key consists of lowercase English letters and ' '.
  • key contains every letter in the English alphabet ('a' to 'z') at least once.
  • 1 <= message.length <= 2000
  • message consists of lowercase English letters and ' '.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate