Given a string str, the task is to find the maximum length K such that there exist two sub-sequences A and B each of length K such that A = B and number of common indices between A and B is at most K – 1.
Input: str = “geeksforgeeks”
The two subsequences are
str[0…1] + str[3…12] = “geksforgeeks”
and str + str[2…12] = “geksforgeeks”.
Input: str = “abcddefg”
Approach: Find any pair of the same letter with a minimum number of letters between them let say this minimum number be X, now the answer of the problem is len(str) – (X + 1). One is added in X to not take count of one letter from the pair.
Below is the implementation of the above approach:
Time Complexity: O(n) where n is the length of the input string.
- Count the number of subsequences of length k having equal LCM and HCF
- Number of subsequences of maximum length K containing no repeated elements
- Find all combinations of two equal sum subsequences
- Minimum index i such that all the elements from index i to given index are equal
- Program to find the maximum difference between the index of any two different numbers
- Find the first maximum length even word from a string
- Find maximum sum possible equal sum of three stacks
- Find three integers less than or equal to N such that their LCM is maximum
- Count unique subsequences of length K
- Number of K length subsequences with minimum sum
- Number of palindromic subsequences of length k where k <= 3
- Find the Increasing subsequence of length three with maximum product
- Find Maximum Length Of A Square Submatrix Having Sum Of Elements At-Most K
- Find four factors of N with maximum product and sum equal to N | Set 3
- Find the minimum of maximum length of a jump required to reach the last island in exactly k jumps
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.