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
- Check if two strings have a common substring
- Check if two strings can be made equal by swapping one character among each other
- Longest Common Prefix using Character by Character Matching
- Number of common base strings for two strings
- Common characters in n strings
- Interleaving of two given strings with no common characters
- Count common subsequence in two strings
- LCS (Longest Common Subsequence) of three strings
- Count common characters in two strings
- Longest common anagram subsequence from N strings
- Longest Common Substring in an Array of Strings
- Count the number of common divisors of the given strings
- Meta Strings (Check if two strings can become same after a swap in one string)
- Print common characters of two Strings in alphabetical order
- Sub-strings of length K containing same character
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.