2
* @param {string[]} ideas5
var distinctNames = function (ideas) {9
for (let i = 0; i < ideas.length; i++) {11
// extract first letter12
let l = idea[0].charCodeAt() - 97;14
let s = idea.substr(1);15
// group substring by first letter17
// must use map not array28
for (let i = 1; i < 26; i++) {29
for (let j = 0; j < i; j++) {30
// count substring with different first letter32
let m1 = lMap.has(i) ? lMap.get(i) : new Map();33
let m2 = lMap.has(j) ? lMap.get(j) : new Map();34
// both map must exist35
if (m1.size > 0 && m2.size > 0) {36
let k1 = Array.from(m1.keys());37
for (let k = 0; k < k1.length; k++) {42
// the rest substring satisfy condition43
res += (m1.size - m) * (m2.size - m);47
// double for count A + B and B + A