Swapping positions
Practice
4.3 (29 votes)
Ad Hoc
Algorithms
Basic programming
Basics of implementation
Easy
Implementation
Problem
86% Success 6959 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code
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
Submissions
Please login to view your submissions
Similar Problems
Points:20
14 votes
Tags:
Basic ProgrammingBasics of ImplementationEasyImplementation
Points:20
25 votes
Tags:
ApprovedEasy
Points:20
159 votes
Tags:
Ad-HocApprovedEasyOpen
Editorial