Your question is Minimum Swaps to Match Strings. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
A PhonePe mobile flow receives two representations of the same token with characters in different positions. Given two strings, compute the minimum number of arbitrary swaps of characters in the first string required to transform it into the second.
A swap may exchange characters at any two positions. Return -1 if the strings cannot be made equal. To make the mapping unambiguous, every character appears at most once in each string.
Implement minimum_swaps(source, target):
source and target containing distinct lowercase English letters.-1 if transformation is impossible.def minimum_swaps(source, target):