All Tracks Basic Programming Implementation Basics of Implementation Problem

Swapping positions
Tag(s):

Ad-Hoc, Algorithms, Basic Programming, Basics of Implementation, Easy, Implementation

Problem
Editorial
Analytics

You are given two strings \(s\) and \(t\) of length \(n\). You can select any two positions (can be from the same or different strings) and swap the characters at those two positions. You have to perform this operation exactly once in such a way that there exists maximum one position \(i\) \((1 \le i \le n)\) such that \(s_i !=t_i\)
Determine whether it is possible to perform the operation such that the given condition holds or not.

Input format

  • First line: A single integer \(T\) that denotes the number of test cases 
  • For each test case:
    • First line: An integer \(n\) 
    • Next two lines: Strings \(s\) and \(t\) respectively

Output format

For each test case, print YES if a valid operation exists otherwise print NO in a single line.

Input constraints

  • \(1 \le T \le 50\)
  • \(1 \le n \le 10^3\)
  • Both the strings \(s\) and \(t\) contain only lowercase English alphabets
SAMPLE INPUT
2
8
mrxismrx
mryismry
8
iamnomrx
iamdamry
SAMPLE OUTPUT
YES
NO
Explanation

In the first test case, we can get a valid result by swapping the characters \(s_3\) and \(t_8\) (1 based indexing).

Time Limit: 2.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

HourStorm #6

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?