Problem Description: You are given two arrays a1 and a2 of strings. Each string is composed with letters from a to z. Let x be any string in the first array and y be any string in the second array.
Find max(abs(length(x) − length(y)))
If a1 or a2 are empty return -1 in each language except in Haskell where you will return Nothing.
Example:
s1 = ["hoqq", "bbllkw", "oox", "ejjuyyy", "plmiis", "xxxzgpsssa", "xxwwkktt", "znnnnfqknaz", "qqquuhii", "dvvvwz"]
s2 = ["cccooommaaqqoxii", "gggqaffhhh", "tttoowwwmmww"]
mxdiflg(s1, s2) --> 13
Level:7kyu
Link to kata: Maximum length difference
In this Kata we are given two arrays with a variable number of strings. We have to find the maximum difference of length of two strings from both the arrays. We start solving this by initializing 2 empty arrays. We start to loop through the first input array and store the length of each string in the first initialized array. We do the same for second input array and store the length of each string in second initialized array.
Once we have got length of all the strings of two input arrays in our two new arrays we sort those two arrays in ascending order using Javascript prototype so that we can have length of strings from shortest to the longest string. Then we find the absolute difference of first element of first array and last element of second array. We also find the absolute difference of last element of first array and first element of second array.
Then we return the maximum of these two differences using Javascript Math.max function as our output.
Here is a link to the code: Kata Day 23
Please mention your suggestions or your doubts in the comment below.
Happy coding. :)
No comments:
Post a Comment