Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Buddy Strings (easy)
Table of Contents

Problem Statement

Examples

Try it yourself

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

. . . .
Mark as Completed

Table of Contents

Problem Statement

Examples

Try it yourself