Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Make Strings Equal

Minimum Swaps to Make Strings Equal gives two equal-length strings. In one move, swap one character from each string, then return the fewest swaps needed to make them identical, or -1 if it is impossible.

Statement

You are given two strings s1 and s2 of equal length, consisting only of the characters 'x' and 'y'.

In one operation, you can choose an index from s1 and an index from s2, then swap the characters at those positions.

Return the minimum number of swaps required to make both strings equal. If it is impossible to make them equal, return −1-1.

Constraints:

  • 1≤1 \leq s1.length, s2.length ≤1000\leq 1000

  • s1.length == s2.length

  • s1 and s2 consist only of 'x' and 'y'.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Make Strings Equal

Minimum Swaps to Make Strings Equal gives two equal-length strings. In one move, swap one character from each string, then return the fewest swaps needed to make them identical, or -1 if it is impossible.

Statement

You are given two strings s1 and s2 of equal length, consisting only of the characters 'x' and 'y'.

In one operation, you can choose an index from s1 and an index from s2, then swap the characters at those positions.

Return the minimum number of swaps required to make both strings equal. If it is impossible to make them equal, return −1-1.

Constraints:

  • 1≤1 \leq s1.length, s2.length ≤1000\leq 1000

  • s1.length == s2.length

  • s1 and s2 consist only of 'x' and 'y'.