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

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

Step by Step Solution

3.43 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Assunptions s and t are having same length comparison is done between only ith element of s with ith ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!