s1
to it.level
to keep track of the number of swaps made so far.s2
, return level
as the answer.
ii. Find the first index where the current string and s2
differ.
iii. Generate all possible strings by swapping the character at the differing index with characters at subsequent indices that would make the string more similar to s2
.
iv. For each generated string, if it has not been visited, add it to the queue and mark it as visited.
b. Increment level
.s1
and s2
are guaranteed to be anagrams).