// Java program for the above approach
import java.util.*;
class GFG
{
// Map for memoization
private static HashMap<String, Integer> mp = new HashMap<>();
// Function to find lcs
// with no repeating character
static int find(String s1, String s2, int N, int M,int store)
{
if (N == 0 || M == 0)
return 0;
String temp = String.valueOf(N) + '#'
+ String.valueOf(M) + '#'
+ String.valueOf(store);
if (mp.containsKey(temp))
return mp.get(temp);
// If the characters are same
if (s1.charAt(N - 1) == s2.charAt(M - 1)
&& ((store >> (s1.charAt(N - 1) - 'a'))
& 1)
== 0) {
store = (store | (1 << (s1.charAt(N - 1)- 'a')));
mp.put(temp,1 + find(s1, s2, N - 1,M - 1, store));
return mp.get(temp);
}
// if the characters are different
else
{ mp.put(temp,Math.max(find(s1, s2, N - 1,
M, store),
find(s1, s2, N, M - 1,
store)));
return mp.get(temp); }
}
// Driver Code
public static void main(String args[]) {
String s1, s2;
s1 = "aabbcc";
s2 = "aabc";
int store = 0;
System.out.println(find(s1, s2, s1.length(), s2.length(), store));
}
}
// This code is contributed by Pushpesh Raj