Two strings are given and you have to modify 1st string such that all the common characters of the 2nd strings have to be removed and the uncommon characters of the 2nd string have to be concatenated with uncommon characters of the 1st string.
Input : S1 = "aacdb" S2 = "gafd" Output : "cbgf" Input : S1 = "abcs"; S2 = "cxzca"; Output : "bsxz"
This problem has existing solution please refer Concatenated string with uncommon characters of two strings link. We can solve this problem quickly in Python using Set and List Comprehension. Approach is simple,
- Convert both strings into set so that they could have only unique characters. Now take intersection of two sets to get common character both strings have.
- Now separate out those characters in each string which are not common in both of them and concatenate the characters.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Concatenated string with uncommon characters of two strings
- Python - String uncommon characters
- Find uncommon characters of the two strings
- Find uncommon characters of the two strings | Set 2
- Generate a string whose all K-size substrings can be concatenated to form the given string
- Python - Convert Dictionary to Concatenated String
- Nth character in Concatenated Decimal String
- Print Kth character in sorted concatenated substrings of a string
- Maximum Consecutive Zeroes in Concatenated Binary String
- Print the final string when minimum value strings get concatenated in every operation
- Python program to find uncommon words from two Strings
- Python | Uncommon elements in Lists of List
- Longest Uncommon Subsequence
- Shortest Uncommon Subsequence
- Find index i such that prefix of S1 and suffix of S2 till i form a palindrome when concatenated
- Count the nodes of the tree which make a pangram when concatenated with the sub-tree nodes
- Python program to print k characters then skip k characters in a string
- Min flips of continuous characters to make all characters same in a string
- String with k distinct characters and no same characters adjacent
- Permutation of a string with maximum number of characters greater than its adjacent characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Code_Mech