Problem Description: Take 2 strings s1 and s2 including only letters from ato z. Return a new sorted string, the longest possible, containing distinct letters, - each taken only once - coming from s1 or s2.
Examples:
a = "xyaabbbccccdefww"
b = "xxxxyyyyabklmopq"
longest(a, b) -> "abcdefklmopqwxy"
a = "abcdefghijklmnopqrstuvwxyz"
longest(a, a) -> "abcdefghijklmnopqrstuvwxyz"
Level: 7kyu
Link to Kata: Two to one
Given the two strings we first split them into two arrays using a split function and then join both these arrays into a single array using the concatenate function.
We then sort the larger concatenated array and initialize a new answer array. We loop through the larger array and if the index of an element from larger array is equal to -1 in the answer array, we push that particular element to answer array.
Once we have completely gone through the concatenated array we join the answer array into a single string using a join function and then return that string.
Here is a link to the code: Kata Day 7
Please mention your suggestions or your doubts in the comment below.
Happy coding. :)
No comments:
Post a Comment