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
- String matching with * (that matches with any) in any of the two strings
- Number of common base strings for two strings
- Longest Common Prefix using Character by Character Matching
- Check if there exists any sub-sequence in a string which is not palindrome
- 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
- Check if characters of a given string can be used to form any N equal strings
- 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
- Print common characters of two Strings in alphabetical order
- Python code to print common characters of two Strings in alphabetical order
- Count common subsequence in two strings
- Count common characters in two strings
- Maximum number of characters between any two same character in a string
- Check if the frequency of any character is more than half the length of the string
- Count number of binary strings such that there is no substring of length greater than or equal to 3 with all 1's
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.