AmazonOA #140
Equal Products
Estimated EasyJudge-ready
Each operation picks two distinct lowercase letters and swaps all of their occurrences in the whole string; one of the letters may currently be absent. For each pair of equal-length strings, decide whether the transformation is possible and output 1 or 0.
Input
The first line contains n (1..100000), followed by n lines, each with two non-empty lowercase strings of equal length. Each string has length ≤200000, and the total length of all strings is ≤500000.
Output
Output n values, each 0 or 1, in input order.
Example 1
Input:
1
abba adda
Output:
1
Example 2
Input:
1
azzel apple
Output:
1
Example 3
Input:
2
ab aa
aba xyx
Output:
0 1
Example notes
Example 1: swapping b and d is enough, so output 1. Example 2: swap z and p, then swap e and l, so output 1. Example 3: the two characters of ab cannot both become a, so output 0; aba can map to xyx, so output 1.
Editorial
Loading solution…