Design Gurus Logo
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 a results in "yx", which matches string b.
  • Example 2:

    • Input: a = "ab", b = "cd"
    • Expected Output: false
    • Justification: There are differences at every position, and swapping any characters in a cannot make it equal to b.
  • Example 3:

    • Input: a = "abcde", b = "acbde"
    • Expected Output: true
    • Justification: Swapping 'b' and 'c' in string a results in "acbde", which matches string b.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory