Isomorphic strings

Check if two strings, str1 and str2, isomorphic by checking if there is a one-to-one mapping for every character of str1 to every character of str2.

Hint

When both strings have the same length, go through each letter in both strings. If the number of times a letter appears in the first string's counter is different from the number of times it appears in the second string's counter, the strings are not the isomorphic.

# Python implementation
output = True

s1 = "ooh"
s2 = "tty"

if len(s1) == len(s2):
  m1 = {}
  m2 = {}

  for i in range(len(s1)):
    if s1[i] not in m1: m1[s1[i]] = i
    if s2[i] not in m2: m2[s2[i]] = i

    if m1[s1[i]] != m2[s2[i]]:
      output = False
      break
else:
  output = False

print(output)
// Javascript implementation
let output = true;

const s1 = "ooh";
const s2 = "tty";

if (s1.length === s2.length) {
  const m1 = {};
  const m2 = {};

  for (let i = 0; i < s1.length; i++) {
    if (!(s1[i] in m1)) m1[s1[i]] = i;
    if (!(s2[i] in m2)) m2[s2[i]] = i;

    if (m1[s1[i]] !== m2[s2[i]]) {
      output = false;
      break;
    }
  }
} else {
  output = false;
}

console.log(output);