Code RoomCharacter substitution mapping
MediumPrep Room Coding #448

Character substitution mapping

CodingDatabases & SQLAlgorithms & data structuresEntry–Mid~15 min

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"}.

Implement
decode_map(coded: str, plain: str) → dict[str,str]
Examples
in["abca","xyzx"]out{"a":"x","b":"y","c":"z"}
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
["abca","xyzx"]{"a":"x","b":"y","c":"z"}not run yetsample