> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Ambiguous Coordinates Python Solution

> Tested Python solution for LeetCode 816 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 816, [Medium](/catalog/medium). Topics: [String](/catalog/topics/string), [Backtracking](/catalog/topics/backtracking), [Enumeration](/catalog/topics/enumeration). [View on LeetCode](https://leetcode.com/problems/ambiguous-coordinates/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 816   # by problem number
lcpy gen -s ambiguous_coordinates   # by problem name
```

## Problem

We had some 2-dimensional coordinates, like `"(1, 3)"` or `"(2, 0.5)"`. Then, we removed all commas, decimal points, and spaces and ended up with the string `s`.

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

Return *a list of strings representing all possibilities for what our original coordinates could have been*.

Our original representation never had extraneous zeroes, so we never started with numbers like `"00"`, `"0.0"`, `"0.00"`, `"1.0"`, `"001"`, `"00.01"`, or any other number that can be represented with fewer digits. Also, a decimal point within a number never occurs without at least one digit occurring before it, so we never started with numbers like `".1"`.

The final answer list can be returned in any order. All coordinates in the final answer have exactly one space between them (occurring after the comma.)

### Examples

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

```
Input: s = "(0123)"
Output: ["(0, 1.23)","(0, 12.3)","(0, 123)","(0.1, 2.3)","(0.1, 23)","(0.12, 3)"]
```

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

### Constraints

* `4 <= s.length <= 12`
* `s[0] == '('` and `s[s.length - 1] == ')'`.
* The rest of `s` are digits.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ambiguous_coordinates/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/ambiguous_coordinates/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n^4) with n <= 10: n-1 split points, each side yields at most 2 valid forms
    # Space: O(n^2) output, all coordinate strings
    def ambiguous_coordinates(self, s: str) -> list[str]:
        def forms(digits: str) -> list[str]:
            out: list[str] = []
            for i in range(1, len(digits) + 1):
                head, tail = digits[:i], digits[i:]
                if head != "0" and head.startswith("0"):
                    continue
                if tail.endswith("0"):
                    continue
                out.append(head + "." + tail if tail else head)
            return out

        results: list[str] = []
        digits = s[1:-1]
        for i in range(1, len(digits)):
            for left in forms(digits[:i]):
                for right in forms(digits[i:]):
                    results.append("(" + left + ", " + right + ")")
        return results
```

## Complexity

| Time | Space |
| - | - |
| O(n^4) with n \<= 10: n-1 split points, each side yields at most 2 valid forms | O(n^2) output, all coordinate strings |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.