Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a new algorithm within strings module #890

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Thejas-1
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant