Given a set of strings of the same length, we need to find the length of the longest string which is a prefix string of at least two strings.
Input: ["abcde", "abcsd", "bcsdf", "abcda", "abced"] Output: 4 Explanation: Longest prefix string is "abcd". Input: ["pqrstq", "pwxyza", "abcdef", "pqrstu"] Output: 5
- Starting from 0th position iterate over every character and check if that character occurs in at least two of the string at the current position or not.
- If occurs, then recursively call on next position. Otherwise,
- Update the max value by taking maximum with Current_position – 1.
- At last, return the max value.
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.
- Find the longest common prefix between two strings after performing swaps on second string
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Longest string in an array which matches with prefix of the given string
- Print the longest prefix of the given string which is also the suffix of the same string
- Sub-strings of a string that are prefix of the same string
- Print the longest palindromic prefix of a given string
- Longest prefix in a string with highest frequency
- Strings from an array which are not prefix of any other string
- String from prefix and suffix of given two strings
- Longest Palindrome in a String formed by concatenating its prefix and suffix
- Count of strings whose prefix match with the given string to a given length k
- Find the longest string that can be made up of other strings from the array
- Longest palindromic String formed using concatenation of given strings in any order
- Minimize length of prefix of string S containing all characters of another string T
- Find length of longest subsequence of one string which is substring of another string
- Longest sub string of 0's in a binary string which is repeated K times
- Given a string and an integer k, find the kth sub-string when all the sub-strings are sorted according to the given condition
- Number of sub-strings which are anagram of any sub-string of another string
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 : bgangwar59