Trains the technique from
LeetCode 854K-Similar StringsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two blend codes s1 and s2 are the same length and use only the letters 'a' through 'f'. They are rearrangements of each other, so each letter appears the same number of times in both.
One swap exchanges the letters at two positions of s1. Return the fewest swaps that turn s1 into s2.
Example 1
Swapping the first two letters gives "bacd", and swapping the last two gives "badc".
Example 2
Swapping the first two letters gives "bac", and swapping the last two gives "bca".
Example 3
The two codes already read the same, so no swap is needed.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def fewest_code_swaps(s1: str, s2: str) -> int:public int fewestCodeSwaps(String s1, String s2)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.