FunctionRacerProblemsRace

Buddy Strings

EasyStringsPython, JavaScript, TypeScript, Java, C++

A swap exchanges the characters at two different positions of s. Return True if exactly one swap of two positions of s makes it equal to goal, otherwise False. Note that you must make a swap, so if s already equals goal you need two equal letters to swap.

Example 1

s "ab"
goal "ba"
returns true

Swap the two letters.

Example 2

s "ab"
goal "ab"
returns false

Swapping always changes it, so False.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems