Search⌘ K
AI Features

Solution: Check if One String Swap Can Make Strings Equal

Explore how to verify if two strings can be made equal by performing at most one swap of characters in one string. Learn to track differing indices and apply a simple check to determine if a single swap can resolve the differences. This lesson helps you understand the problem approach, analyze time and space complexity, and implement the solution confidently in Go.

Statement

You are given two strings s1 and s2 of equal length. A string swap operation allows you to choose two indices in a string (not necessarily different) and swap the characters at those indices.

Determine whether it is possible to make the two strings equal by performing at most one string swap on exactly one of the strings. Return TRUE if this is possible, and FALSE otherwise.

Note: The swap is performed on exactly one of the two strings, and you may choose to perform zero or one swap.

Constraints:

  • 11 \leq ...