Trains the technique from
LeetCode 205Isomorphic StringsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two depots label the same delivery run with their own character codes, first and second, of equal length. Dispatch wants to know whether the two labels describe the same run under a consistent relabelling of characters.
Call the codes interchangeable when there is a substitution table that turns first into second position by position, subject to two rules:
first must be substituted by the same character in secondfirst may be substituted by the same character of secondA character is allowed to substitute to itself. Codes may contain any ASCII characters, including digits, spaces and punctuation, and uppercase is a different character from lowercase. Return true when the codes are interchangeable and false otherwise.
Example 1
Substituting m for t and i for o rewrites the first label as the second, and the repeated character stays consistent at both ends.
Example 2
The single character of the first label would have to become two different characters, which no substitution table allows.
Example 3
The blank counts as an ordinary character and maps to itself, while d, i and p take three distinct partners.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def codes_interchangeable(first: str, second: str) -> bool:public boolean codesInterchangeable(String first, String second)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.