Palindrome Swapping

3.9

7 votes
Algorithms, Basics of String Manipulation, String Algorithms
Problem

Problem Statement

There are given two strings S and T consisting of lowercase English letters, both of same length. Let’s say length of both strings is N.  

Is it possible to make both strings equal by doing following changes any number of times :

  • Choose any index i(0i<n) and swap Si and Ti
  • Choose any index i(0i<n) and swap Si and Sni1
  • Choose any index i(0i<n) and swap Ti and Tni1

Input Format

First line contains a String S.

Second line contains a String T.

Output Format

Print “YES” (without quotes) if you can make S and T equal . Else print “NO” (without quotes) .

Constraints

1N105.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

You can swap S(0) and S(4) . You can swap S(1) and S(3) for getting both strings equal . 

Editor Image

?