2325. Decode the Message
Description
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
keyas the order of the substitution table.Align the substitution table with the regular English alphabet.
Each letter in
messageis then substituted using the table.Spaces
' 'are transformed to themselves.For example, given
key = "hap py bo y"(actual key would have at least one instance of each letter in the alphabet), we have the partial substitution table of ('h' -> 'a','a' -> 'b','p' -> 'c','y' -> 'd','b' -> 'e','o' -> 'f').
Return the decoded message.
Example 1:
1 | Input: key = "the quick brown fox jumps over the lazy dog", message = "vkbs bs t suepuv" |
Example 2:
1 | Input: key = "eljuxhpwnyrdgtqkviszcfmabo", message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb" |
Constraints:
26 <= key.length <= 2000keyconsists of lowercase English letters and' '.keycontains every letter in the English alphabet ('a'to'z') at least once .1 <= message.length <= 2000messageconsists of lowercase English letters and' '.
Hints/Notes
- 2025/05/05 Q1
- String
- No solution from 0x3F or Leetcode
Solution
Language: C++
1 | class Solution { |