Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Leetcode 1247. Minimum Swaps to Make Strings Equal
Given two equal-length strings of only 'x' and 'y', compute the minimum number of swaps between the strings (swap s1[i] with s2[j]) to make them identical or return -1 if impossible. Key idea: count mismatches of type "s1='x', s2='y'" and "s1='y', s2='x'"; pair same-type mismatches (one swap per pair) and handle any two opposite leftovers with two swaps, otherwise it's impossible if total mismatches is odd.
Asked at:
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late November, 2024
Mid-level
Find the minimum number of contiguous swaps required to transform one list of strings into another. Given two lists of strings with the same set of elements and no duplicates within each list, determine the minimum number of adjacent element swaps needed to convert one list into the other.
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.