Tap here to switch tabs
Problem
Submissions

Problem: Minimum Swaps to Make Strings Equal

Try to solve the Minimum Swaps to Make Strings Equal problem.

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

Try to solve the Minimum Swaps to Make Strings Equal problem.

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'.