Baseline Strings · Easy O(n) · O(1)
A cipher vault replaces each plaintext letter with a ciphertext letter through a fixed substitution table, and an auditor receives two transcripts claimed to be encodings of the same message. The substitution must be consistent: one source letter always becomes the same target letter, and no two different source letters may collapse onto the same target. The auditor certifies the pair only when such a flawless mapping exists.
Input: Two strings s and t of equal length.
Output: true when the characters of s can be replaced to produce t under a consistent one-to-one mapping, false otherwise.
1 <= s.length <= 5 * 10^4s.length == t.lengths and t consist of lowercase English lettersInput: {"s":"egg","t":"add"}
Output: true
e maps to a and g maps to d; both replacements hold at every occurrence.
Input: {"s":"foo","t":"bar"}
Output: false
The two o's in s would need to become a and r simultaneously, which no single mapping allows.