Choose two different strings from ideas in an ordered pair, then swap their first letters. The pair is valid only when neither resulting string appears anywhere in the original ideas list. A valid company name consists of the two resulting strings, in that order, separated by one space. Return the number of distinct valid company names. Reversing a valid pair produces a different name and must be counted separately. All original ideas are unique.
Example 1:
Input: ideas = ["ax","by"]
Output: 2Explanation: Swapping the initial letters gives bx and ay, neither of which is an original idea. The two ordered company names are "bx ay" and "ay bx", so return 2.
Example 2:
Input: ideas = ["ax","bx"]
Output: 0Explanation: Swapping first letters produces bx and ax, both already present in ideas. Neither ordering is valid, so return 0.
Example 3:
Input: ideas = ["ax","ay","bz"]
Output: 4Explanation: Pair ax with bz to create "bx az" and its reverse, and pair ay with bz to create "by az" and its reverse. Pairing ax with ay leaves existing ideas unchanged. There are four valid names.
Constraints:
2 <= ideas.length <= 50000- Each idea contains between
1and10lowercase English letters. - All ideas are distinct.