Palindrome Swapping
Practice
3.9 (7 votes)
Algorithms
Basics of string manipulation
String algorithms
Problem
91% Success 3971 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

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 (0 \leq i < n)\) and swap \(S_i\) and \(T_i\)
  • Choose any index \(i (0 \leq i < n)\) and swap \(S_i\) and \(S_{n-i-1}\)
  • Choose any index \(i (0 \leq i < n)\) and swap \(T_i\) and \(T_{n-i-1}\)

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

\(1 \leq N \leq 10^5\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
AlgorithmsString AlgorithmsBasics of String ManipulationStringData Structures
Points:30
57 votes
Tags:
ReadyMathematicsOpenApprovedEasy-MediumMathamatics
Points:30
9 votes
Tags:
Ad-HocAlgorithmsApprovedMediumOpen