2013
11-11

# Common permutation

Given two strings of lowercase letters, a and b, print the longest string x of lowercase letters such that there is a permutation of x that is a subsequence of a and there is a permutation of x that is a subsequence of b.

Input consists of pairs of lines. The first line of a pair contains a and the second contains b. Each string is on a separate line and consists of at most 1,000 lowercase letters.

For each subsequent pair of input lines, output a line containing x. If several x satisfy the criteria above, choose the first one in alphabetical order.

pretty
women
walking
down
the
street


e
nw
et



//* @author  mekarlos@gmail.com
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
String s=""; int[] l1,l2;
l1=new int[26];l2=new int[26];
for(int i=0;i< s.length();i++){
l1[(int)(s.charAt(i)-'a')]++;
}
for(int i=0;i< s.length();i++){
l2[(int)(s.charAt(i)-'a')]++;
}
for(int i=0;i< 26;i++){
l1[i]=Math.min(l1[i], l2[i]);
}
for(int i=0;i< 26;i++){
for(int j=0;j< l1[i];j++){
System.out.print((char)(i+'a'));
}
}
System.out.print("\n");
}
}
}

1. Excellent Web-site! I required to ask if I might webpages and use a component of the net web website and use a number of factors for just about any faculty process. Please notify me through email regardless of whether that would be excellent. Many thanks