Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Assunptions s and t are having same length comparison is done between only ith element of s with ith ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started