203. Decode the Message

EasyStringString

You are given two strings key and message.

The key is a permutation of the alphabet used to create a substitution cipher:
- Non-space characters appear in key in the order they first appear; each maps to a→b→c→... in order.
- Spaces map to spaces.

Decode and return the decoded message.

Input format: key|message

Input: Two '|' separated strings: key and message.

Output: The decoded message string.

Examples

Example 1
Input: the quick brown fox jumps over the lazy dog|vkbs bs t suepuv
Output: this is a secret
Explanation: Build mapping from key's first-occurrence order; decode message.
Example 2
Input: abcdefghijklmnopqrstuvwxyz|hello world
Output: hello world
Explanation: Identity cipher — output equals input.
Example 3
Input: zyxwvutsrqponmlkjihgfedcba|hello world
Output: svool dliow
Explanation: Reversed alphabet cipher.

Constraints

Asked by

GoogleAmazonMeta
Solve this problem in the editor →