# LeetCode: Ambiguous Coordinates Solution

```.css-ds3kc{display:table-row;}.css-1t8atru{display:table-cell;opacity:0.5;padding-right:var(--chakra-space-6);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;text-align:right;}1.css-2qghsv{display:table-cell;}/**2 * @param {string} s3 * @return {string[]}4 */5var ambiguousCoordinates = function (s) {6  s = s.substring(1, s.length - 1)7
8  const generate = s => {9    if (s.length === 1) return [s]10    if (s.startsWith("0") && s.endsWith("0")) return []11    if (s.startsWith("0")) return [`0.\${s.substring(1)}`]12    if (s.endsWith("0")) return [s]13
14    const possible = [s]15    for (let i = 1; i < s.length; i++) {16      possible.push(`\${s.substring(0, i)}.\${s.substring(i)}`)17    }18    return possible19  }20
21  const makePair = (x, y) => `(\${x}, \${y})`22
23  const res = []24
25  for (let i = 1; i < s.length; i++) {26    for (const x of generate(s.substring(0, i))) {27      for (const y of generate(s.substring(i))) {28        res.push(makePair(x, y))29      }30    }31  }32
33  return res34}```

leetcode

string

## Next Post

LeetCode: Flatten Binary Tree To Linked List

May 14, 2021

Search Posts