#816

Ambiguous Coordinates

specialist · 835 · lc medium +31 · verified · 56.5% accepted · 340 likes · top 51%

Description

Suppose we had 2-dimensional coordinates such as "(1, 3)" or "(2, 0.5)". We stripped all commas, decimal points, and spaces, producing a compact string s.

- For example, "(1, 3)" becomes s = "(13)" and "(2, 0.5)" becomes s = "(205)".

Return all possible original coordinate pairs that could have produced s.

No extraneous leading zeros were present in the originals (e.g., numbers like "00", "0.0", "001", or "00.01" would not appear), and every decimal point is preceded by at least one digit (so ".1" is not valid).

All answers must have exactly one space after the comma. The result may be returned in any order.

Example 1:

Input: s = "(123)"
Output: ["(1, 2.3)","(1, 23)","(1.2, 3)","(12, 3)"]

Example 2:

Input: s = "(0123)"
Output: ["(0, 1.23)","(0, 12.3)","(0, 123)","(0.1, 2.3)","(0.1, 23)","(0.12, 3)"]
Explanation: 0.0, 00, 0001 or 00.01 are not allowed.

Example 3:

Input: s = "(00011)"
Output: ["(0, 0.011)","(0.001, 1)"]

Code

1
2
3