Code Room
CodingMediumcod-g1265
Subject HashingLevel Entry–Mid~15 minCommon in Databases & SQL · Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.