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.)

&nbsp;
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)"]


&nbsp;
Constraints:


	4 &lt;= s.length &lt;= 12
	s[0] == '(' and s[s.length - 1] == ')'.
	The rest of s are digits.


class Solution(object):
    def ambiguousCoordinates(self, s):
        """
        :type s: str
        :rtype: List[str]
        """
        def _isValidSplit(s):
            return False if len(s)>1 and re.match('/^[0]+$/',s) else True

        def _isValidNum(ipart,fpart):
            return False if (len(ipart)>1 and ipart[0]=='0') or (fpart and fpart[-1]=='0') else True

        def _splitToNums(s):
            rets=[]
            if len(s)==1:return [s]
            for i in range(1,len(s)+1):
                a,b=s[:i],s[i:]
                if _isValidNum(a,b):rets.append("%s.%s"%(a,b) if b else "%s"%(a))
            return rets

        ans,s=[],s[1:-1]
        for i in range(1,len(s)):
            a,b=s[:i],s[i:]
            if not _isValidSplit(a) or not _isValidSplit(b):continue
            for c1,c2 in itertools.product(_splitToNums(a),_splitToNums(b)):ans.append("(%s, %s)"%(c1,c2))
        return ans
class Solution {
    public List<String> ret;
    public List<String> ans;
    public List<String> ambiguousCoordinates(String s) {
        ret=new ArrayList<>();
        ans=new ArrayList<>();
        String start=s.substring(0,2);
        util(s,1);
        fun();
        return ans;
    }
    
    //putting comma
    void util(String s,int idx) {
        if(idx==s.length()-2) {
            return;
        }
        
        String ns=s.substring(0,idx+1)+", "+s.substring(idx+1);
        ret.add(ns);
        util(s,idx+1);
    }
    
    //helper function for puting decimals after comma
    void fun() {
        for(String s:ret) {
            int cIndex=0;
            for(int i=0;i<s.length();i++) {
                if(s.charAt(i)==',') {
                    cIndex=i;
                    break;
                }
            }
            String a=s.substring(1,cIndex);
            String b=s.substring(cIndex+2,s.length()-1);
            List<String> n1=dot(a);
            List<String> n2=dot(b);
            if(n1==null || n2==null) { //invalid strings
                continue;
            }else { //valid strings
                for(String fir:n1) {
                    for(String sec:n2) {
                        ans.add("("+fir+", "+sec+")");
                    }
                }
            }
        }
    }
    
    //putting decimal point
    List<String> dot(String n) {
        List<String> li=new ArrayList<>();
        if(n.length()==1) {
            li.add(n);
        }else {
            
            //just checking for first and last zeroes and making conditions accordingly

            if(n.charAt(n.length()-1)=='0') {
                if(n.charAt(0)=='0') {
                    return null;
                }else {
                    li.add(n);
                }
            }else if(n.charAt(0)=='0') {
                li.add("0."+n.substring(1));
            }else {
                for(int i=0;i<n.length()-1;i++) {
                    li.add(n.substring(0,i+1)+"."+n.substring(i+1));
                }
                li.add(n);  //without any decimal
            }
        }
        return li;
    }
}
class Solution {
public:
    vector<string> check(string s){
        int n = s.size();
        vector<string> res;
        if(s[0] == '0'){
            if(n == 1)
                res.push_back(s);
            else{
                if(s[n-1] == '0')
                    return res;
                
                s.insert(1, ".");
                res.push_back(s);
            }
        }
        else{
            if(s[n-1] == '0'){
                res.push_back(s);
                return res;
            }
            
            for(int i=1; i<n; i++){
                string t = s.substr(0, i) + "." + s.substr(i, n-i);
                res.push_back(t);
            }
            res.push_back(s);
        }
        
        return res;
    }
    vector<string> ambiguousCoordinates(string s) {
        int n = s.size();
        vector<string> res;
        
        for(int i=2; i<n-1; i++){
            vector<string> left = check(s.substr(1, i-1));
            vector<string> right = check(s.substr(i, n-i-1));
            for(int j=0; j<left.size(); j++){
                for(int k=0; k<right.size(); k++){
                    string t = "(" + left[j] + ", " + right[k] + ")";
                    res.push_back(t);
                }
            }
        }
        
        return res;
    }
};
var ambiguousCoordinates = function(S) {
    let ans = [], xPoss
    const process = (str, xy) => {
        if (xy)
            for (let x of xPoss)
                ans.push(`(${x}, ${str})`)
        else xPoss.push(str)
    }
    const parse = (str, xy) => {
        if (str.length === 1 || str[0] !== "0")
            process(str, xy)
        if (str.length > 1 && str[str.length-1] !== "0")
            process(str.slice(0,1) + "." + str.slice(1), xy)
        if (str.length > 2 && str[0] !== "0" && str[str.length-1] !== "0")
            for (let i = 2; i < str.length; i++)
                process(str.slice(0,i) + "." + str.slice(i), xy)
    }
    for (let i = 2; i < S.length - 1; i++) {
        let strs = [S.slice(1,i), S.slice(i, S.length - 1)]
        xPoss = []
        for (let j = 0; j < 2; j++)
            if (xPoss.length || !j) parse(strs[j], j)
    }
    return ans
};
Ambiguous Coordinates