Added a new algorithm within strings module #890
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So I came across this interesting problem that requires us to swap just one character amongst the two strings that are given to us. Once the swap is complete, the strings should contain the same number of distinct characters (The characters need not be the same in the two strings). The function should return True if it is possible to make such a swap and False otherwise.
For Example, if we are given two strings 'ddef' and 'dde', we can swap characters f from string 1 and d from string 2. Hence, our final strings will be 'dded' and 'fde', which will contain three distinct characters each (the duplicate characters count as 1) and the algorithm should return True.
On the other hand, if we are given two strings 'cd' and 'e', irrespective of swapping characters c and d from string 1 with the character e in string 2, we will always have two distinct characters in string 1 and 1 character in string 2. Hence, the algorithm returns False.