Skip to content

Practice Check if One String Swap Can Make Strings Equal

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1790
LeetCode Problem

Check if One String Swap Can Make Strings Equal

Problem Statement

You are given two strings s1 and s2 of equal length. A string swap is an operation where you choose two indices in a string (not necessarily different) and swap the characters at these indices. Return true if it is possible to make both strings equal by performing at most one string swap on exactly one of the strings. Otherwise, return false.

Source: Check if One String Swap Can Make Strings Equal on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s1 = "bank", s2 = "kanb"
Output
true

# Example 2

Input
s1 = "attack", s2 = "defend"
Output
false

# Example 3

Input
s1 = "kelb", s2 = "kelb"
Output
true

Constraints

1 <= s1.length, s2.length <= 100
s1.length == s2.length
s1 and s2 consist of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Check if One String Swap Can Make Strings Equal.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.