Naming a Company

You are given an array of strings ideas that represents a list of names to be used in the process of naming a company. The process of naming a company is as follows:

  • Choose 2 distinct names from ideas, call them ideaA and ideaB.
  • Swap the first letters of ideaA and ideaB with each other.
  • If both of the new names are not found in the original ideas, then the name ideaA ideaB (the concatenation of ideaA and ideaB, separated by a space) is a valid company name.
  • Otherwise, it is not a valid name.

Return the number of distinct valid names for the company.

Example 1
Inputideas = ["coffee","donuts","time","toffee"]
Output6
There are 6 valid ordered selections, including ("coffee", "donuts") producing "doffee conuts" and ("donuts", "coffee") producing "conuts doffee".
Example 2
Inputideas = ["lack","back"]
Output0
There are no valid selections, so 0 is returned.

Constraints

  • 2 <= ideas.length <= 5 * 10^4
  • 1 <= ideas[i].length <= 10
  • ideas[i] consists of lowercase English letters.
  • All the strings in ideas are unique.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate