1. Almost Equivalent Strings Two strings are considered almost equivalent if they have the same length AND...
Fantastic news! We've Found the answer you've been seeking!
Question:
1. Almost Equivalent Strings Two strings are considered almost equivalent" if they have the same length AND for each lowercase letter x, the number of occurrences of xin the two strings differs by no more than 3. There are two string arrays, s and i, that each contains n strings. Strings (i) and (I are the oth pair of strings. They are of equal length and consist of lowercase English letters. For each pair of strings, determine if they are almost equivalent. Example S = ['aabaab, 'aaaaabby t=[bbabbc, 'abb7 Occurrences of a'in s[OJ = 4 and in t[0]= 1, difference is 3 Occurrences of 'b'in s[0] = 2 and in t[0] = 4, difference is 2 Occurrences of 'c'in s[0] = 0 and in t[0] = 1, difference is 1 The number of occurrences of 'a', 'b' and 'c'in the two strings never differs by more than 3. This pair is almost equivalent so the return value for this case is "YES! Occurrences of in s[1] = 5 and in t[1] = 1, difference is 4 Occurrences of 'b'in s[1] = 2 and in t{1} = 2, difference is o The difference in the number of occurrences of 'a'is greater than 3 so the return value for this case is 'NO The return array is ['YES, NO'). Function Description Complete the function areAlmostEquivalent in the editor below. areAlmostEquivalent has the following parameters: string s/n]: an array of strings string tin an array of strings Returns: string(n). an array of strings, either 'YES' or 'NO' in answer to each test case
Related Book For
Posted Date: