Given two strings. The task is to check that is there any common character in between two strings.
Input: s1 = "geeksforgeeks", s2 = "geeks" Output: Yes Input: s1 = "geeks", s2 = "for" Output: No
Approach: Traverse the 1st string and map the characters of the string with its frequency, in this map characters act as a key and the frequency its value. Then traverse the second string and we will check if there is any character that is present in both the string then it is confirmed that there is a common sub-sequence.
Below is the implementation of above approach:
Time Complexity: O(n) where n is the length of the string
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.
- Maximize partitions such that no two substrings have any common character
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
- Check if there exists any sub-sequence in a string which is not palindrome
- Number of common base strings for two strings
- String matching with * (that matches with any) in any of the two strings
- Longest Common Prefix using Character by Character Matching
- Check if two strings have a common substring
- Interleaving of two given strings with no common characters
- Check if two strings can be made equal by swapping one character among each other
- Check if two strings after processing backspace character are equal or not
- Count number of binary strings such that there is no substring of length greater than or equal to 3 with all 1's
- Number of binary strings such that there is no substring of length ≥ 3
- Count substrings of same length differing by a single character from two given strings
- Check if characters of a given string can be used to form any N equal strings
- Count common subsequence in two strings
- Count common characters in two strings
- Print common characters of two Strings in alphabetical order
- Python code to print common characters of two Strings in alphabetical order
- Meta Strings (Check if two strings can become same after a swap in one string)
- Check whether two strings can be made equal by reversing substring of equal length from both strings
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.