Company: Google
Difficulty: medium
Count Isomorphic You have a list of N strings made only of lowercase letters. S[i] denotes the i th string in that list. Task You will receive Q queries, each giving a string K[i]. For every query, count how many strings from the list are isomorphic to K[i]. Notes Two strings, X and Y, are isomorphic when every occurrence of a character in X can be swapped for another character to produce Y, and the reverse swap turns Y back into X. For instance, take the strings "ACAB" and "XCXY". They are isomorphic because mapping 'A' to 'X', 'B' to 'Y', and 'C' to 'C' turns "ACAB" into "XCXY". A character may map to itself, but no single character may stand in for two different characters at once. Example Assumptions: N = 4 Q = 1 S = ["abaca", "efefe", "trtft", "rtrcr"] K = ["hwhoh"] Approach: "abaca", "trtft", "rtrcr" are isomorphic to "hwhoh". "abaca" matches "hwhoh" under the mapping 'a' to 'h', 'b' to 'w', and 'c' to 'o'. "trtft" matches "hwhoh" under the mapping 't' to 'h', 'r' to 'w', and 'f'