Number-Character Bijective Mapping
Problem statement
Given an integer array pattern and an array of candidate strings passcodes, test each passcode independently.
A passcode is valid when it has the same length as pattern and the positions define a bijection between integer values and characters:
- Every occurrence of the same integer maps to the same character.
- Two different integers never map to the same character.
Return a boolean array in query order, where each value states whether the corresponding passcode is valid.
Function
checkBijectiveMappings(pattern: int[], passcodes: String[]) → boolean[]Examples
Example 1
pattern = [1, 2, 1]passcodes = ["aba","abc","xyx","x"]return = [true, false, true, false]aba and xyx preserve the repeated first value. In abc, value 1 maps to two characters, and x has the wrong length.
Example 2
pattern = [7, 7, 8]passcodes = ["aab","abb","aac"]return = [true, false, true]aab and aac assign one character to value 7 and a different character to value 8. In abb, the repeated value 7 maps inconsistently.
Constraints
1 <= pattern.length <= 10^5-10^9 <= pattern[i] <= 10^91 <= passcodes.length <= 10^50 <= passcodes[i].lengthsum of all passcode lengths <= 2 * 10^5- Every passcode contains only ASCII letters or digits.