need to write algorithm for this question in javascript [closed]

given 2 strings p and Q each consisting of N lowercase english letters for each position in the strings we have to choose one letter from either P and Q in order to construct a new String S, such that the number of distinct letters is S is minmal. Our task is to find the number of distinct letters in resulting string for example P=”abc, Q=”bcd”, your function should return 2 all possible strings s that can be constructed are “abc, “abd”, “acc”,”acd”, “bbc”, “bbd”, “bcc”,”bcd the minimum number of dsitinct letters is 2 which be obtained by constructing the follwing strings “acc”, “bbc”,”bbd”, “bcc” given P=”axxz”, Q=”yzwy”, your function should return 2 string S must consist of at least 2 distinct letters in this case we can construct S=”yxxy” where the number of distinct letters is equal to 2 and this is the only optimal solution given P=”bacad
, Q=”abada, your function should return 1 we can choose the letter ‘a’ in each position, so S can be equal to “aaaa”. given P = “amz”, Q=”amz” your function should return 3 the the input string are identical so the only possible S that can be constructed is “amz” and its number of distinct letter is 3 write the efficient algorithm for the follwoing assumption N is an inetger within the range [1…200,000] string P and Q are both of length N strings P and Q are made only of lowercase letters(a-z) string P and Q contain a total of at most 20 distinct letters

Need answer for this javascript question