Tap here to switch tabs
Problem
Submissions

Problem: Buddy Strings

med
30 min
Try to solve the Buddy Strings problem.

Statement

Given two strings s and goal, return true if you can swap two letters in s so the resulting string is equal to goal, or false otherwise.

Swapping letters is defined as taking two indices i and j (zero indexed) such that i≠ji \neq j and swapping the characters at s[i] and s[j].

Constraints:

  • 1≤1 \leq s.length, goal.length ≤2⋅104\leq 2 \cdot 10^4

  • s and goal consist of lowercase letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Buddy Strings

med
30 min
Try to solve the Buddy Strings problem.

Statement

Given two strings s and goal, return true if you can swap two letters in s so the resulting string is equal to goal, or false otherwise.

Swapping letters is defined as taking two indices i and j (zero indexed) such that i≠ji \neq j and swapping the characters at s[i] and s[j].

Constraints:

  • 1≤1 \leq s.length, goal.length ≤2⋅104\leq 2 \cdot 10^4

  • s and goal consist of lowercase letters.