Character substitution mapping

Write codeMedium15 min

Your task

A toy substitution decoder replaces each character of a coded message with exactly one plaintext character; two different coded characters are allowed to decode to the same plaintext character. You are given a coded string and its claimed decoding of the same nominal length. Recover the mapping: return a dictionary from each coded character (one-character string) to its plaintext character. If the strings differ in length, or some coded character would need two different plaintext characters, return an empty dictionary. For example, coded "abca" with plain "xyzx" yields {"a": "x", "b": "y", "c": "z"}.

Examples

decode_map(coded: str, plain: str) -> dict[str,str]
Example 1
Inputdecode_map("abca", "xyzx")
Output{"a": "x", "b": "y", "c": "z"}