MicrosoftOA #71
Word Pattern II (Round 1, LC 291 :)
Estimated MediumJudge-ready
Topics (AI-labelled)Partitioning
Map each distinct character of pattern to a non-empty string, such that the same character always maps to the same string and different characters cannot map to the same string. Concatenate the mapped strings following the pattern, and determine whether the result can be exactly s.
This site uses a standard input/output protocol.
Input
Two lines, pattern and s, both containing only lowercase letters, each of length 1..20.
Output
Output a single integer, the answer.
Example 1
Input:
abab
redblueredblue
Output:
1
Example 2
Input:
aaaa
asdasdasdasd
Output:
1
Example 3
Input:
aabb
xyzabcxyzabc
Output:
0
Example notes
Example 1: a→red and b→blue form the target, so output 1. Example 2: a→asd repeated 4 times matches exactly, so output 1. Example 3: the string cannot be split into two identical a strings followed by two identical b strings, so output 0.
Editorial
Loading solution…