The challenge

Take 2 strings `s1` and `s2` including only letters from `a`to `z`. Return a new sorted string, the longest possible, containing distinct letters – each taken only once – coming from s1 or s2.

Examples:

 ``````1 2 3 4 5 6 `````` ``````a = "xyaabbbccccdefww" b = "xxxxyyyyabklmopq" longest(a, b) -> "abcdefklmopqwxy" a = "abcdefghijklmnopqrstuvwxyz" longest(a, a) -> "abcdefghijklmnopqrstuvwxyz" ``````

The solution in Python code

Option 1 (Using a Dictionary):

 ``````1 2 3 `````` ``````def longest(a1, a2): a3 = list(dict.fromkeys(sorted(a1+a2))) return "".join(a3) ``````

Option 2 (Using a Set):

 ``````1 2 `````` ``````def longest(a1, a2): return "".join(sorted(set(a1 + a2))) ``````

Option 3 (Using a Union):

 ``````1 2 `````` ``````def longest(s1, s2): return ''.join(sorted(set(s1).union(s2))) ``````

Test cases to validate our solution

 `````` 1 2 3 4 5 6 7 8 9 10 `````` ``````import test as test @test.describe("longest") def tests(): @test.it("basic tests") def basics(): test.assert_equals(longest("aretheyhere", "yestheyarehere"), "aehrsty") test.assert_equals(longest("loopingisfunbutdangerous", "lessdangerousthancoding"), "abcdefghilnoprstu") test.assert_equals(longest("inmanylanguages", "theresapairoffunctions"), "acefghilmnoprstuy") ``````