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
- Longest Common Prefix using Character by Character Matching
- Number of common base strings for two strings
- Common characters in n strings
- LCS (Longest Common Subsequence) of three strings
- Count common characters in two strings
- Count common subsequence in two strings
- Count the number of common divisors of the given strings
- Longest Common Substring in an Array of Strings
- Longest common anagram subsequence from N strings
- Count of sub-strings that contain character X at least once
- Sub-strings of length K containing same character
- Sub-strings that start and end with one character and have at least one other
- Character pairs from two strings with even sum
- Print common characters of two Strings in alphabetical order
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 : Krishna_Yadav