747. String Equivalence
During the CodSule 2019 event in India, a tourist and Rajat were discussing problems related to divide and conquer. The tourist asked Rajat if he could determine whether two strings, s1 and s2, are equivalent. Rajat then inquired about the conditions for equivalence, to which the tourist replied:
Two strings, a and b, of equal length are considered equivalent if one of the following conditions is met:
- They are exactly the same.
- If we split string a into two halves of equal size, a1 and a2, and string b into two halves of equal size, b1 and b2, then one of the following must be true:
- a1 is equivalent to b1, and a2 is equivalent to b2
- a1 is equivalent to b2, and a2 is equivalent to b1
Rajat quickly solved the problem. Can you?