words. Double-barrelled names are built from it like this:
1. Pick two different words A and B from the list (order matters: the pair (A, B) differs from (B, A)).
2. Swap their first letters, producing A′ and B′.
3. If neither A′ nor B′ appears in the original list, the string "A′ B′" (the two words joined by a space) is a valid name.
Return the number of distinct valid names.words=['moon', 'sun', 'soon'] → 0
Any swap involving "moon" and an s-word turns "moon" into "soon", which is already listed, and swapping "sun" with "soon" changes nothing. So the answer is 0.
words=['cat', 'dog', 'bat'] → 4
The pair ("cat", "dog") gives "dat" and "cog", neither of which is listed, so "dat cog" is a name; ("dog", "cat") gives "cog dat". The same works for "bat" with "dog". "cat" and "bat" just turn into each other, so they do not count. That makes 4 names.
len(words) ≤ 5·10⁴len(words[i]) ≤ 10words[i] consists of lowercase English letterswords are distinctwords=['moon', 'sun', 'soon']
0
Run checks the first 3 tests in your browser. Submit checks all 26 tests on the server, hidden ones included.