Back to course home
0% completed
Vote For New Content
Buddy Strings (easy)
Problem Statement
Given two strings a and b, return true if they can be considered "buddy strings". Otherwise, return false.
Two strings are buddy strings if you can swap any two letters in one string to make it equal to the other string.
Examples
- 
Example 1: - Input: a = "xy", b = "yx"
- Expected Output: true
- Justification: Swapping 'x' and 'y' in string aresults in "yx", which matches stringb.
 
- Input: 
- 
Example 2: - Input: a = "ab", b = "cd"
- Expected Output: false
- Justification: There are differences at every position, and swapping any characters in acannot make it equal tob.
 
- Input: 
- 
Example 3: - Input: a = "abcde", b = "acbde"
- Expected Output: true
- Justification: Swapping 'b' and 'c' in string aresults in "acbde", which matches stringb.
 
- Input: 
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself