C++ modular code with explanation
The logic is quite simple for this problem. You have to break the strings, at all possible points. Then you have to again break all the formed substrings, by pl
The logic is quite simple for this problem. You have to break the strings, at all possible points. Then you have to again break all the formed substrings, by placing dots in between the substrings, and following the `0` rules.\n\nExample - `(1234)`\n\nAfter removing the brackets, we get `s = 1234`. If you break the string at all points, the substrings you get are-\n\n`1  234`    ->   `1  234`,  `1  2.34`,  `1  23.4`\n`12  34`    ->   `12  34`,  `12  3.4`,  `1.2  34`,  `1.2  3.4`\n`123  4`    ->   `123  4`,  `1.23  4`,  `12.3  4`\n\nAs you can see I broke the substrings again to insert decimals. Of course you can\'t have something like `1.` or `0001` or `1.00`. For that I use a `check function`.\n\nAs you can see after breaking the string at a particular point, I get two substrings `s1` and `s2`. Then I break both of them into `first` and `second`. `first` represents the part before the decimal and `second` is the part after that.\n\nFor `first`, if it\'s length is greater than `1`, then first digit can\'t be `0`. For example `0.xx` or `0` is valid, but something like `01.xx` or `000` is not acceptable. \nSimilarly, for `second`, the last digit cant be `0`. For example `xx.0` or `xx.30` is not valid.\n\nThe reset is simple. I take 2 vectors `res1` (for storing the first coordinates) and `res2` (for storing the second coordinates), and combine them into the final vector.\n\n```\nclass Solution {\npublic:\n\t// issecword denotes if it is the second word (the part after the decimal)\n    bool check(string s, bool issecword)\n    {\n        int n=s.length();\n\t\t// Logic explained above\n        if(issecword){\n            if(n>0 && s[n-1]==\'0\') return false;\n        }\n        else{\n            if(n>1 && s[0]==\'0\') return false;\n        }\n        return true;\n    }\n\n    vector<string> ambiguousCoordinates(string S) {\n        vector<string> res;\n        S=S.substr(1,S.length()-2);  // Remove the brackets\n        int n=S.length();\n\n        for(int i=1;i<n;i++){\n            string s1=S.substr(0,i);\n            string s2=S.substr(i);\n            vector<string> res1, res2;\n\t\t\t\n\t\t\t// The full string without any decimal point can also be a coordinate.\n\t\t\t// But \'01\' or \'001\' is not possible.\n            if(check(s1, false)) res1.push_back(s1);\n            if(check(s2, false)) res2.push_back(s2);\n\t\t\t\n\t\t\t// First co-ordinate\n            for(int j=1;j<s1.length();j++){\n                string first=s1.substr(0,j);\n                string second=s1.substr(j);\n                if(check(first, false) && check(second, true)) res1.push_back(first+"."+second);\n            }\n\t\t\t\n\t\t\t// Second co-ordinate\n            for(int j=1;j<s2.length();j++){\n                string first=s2.substr(0,j);\n                string second=s2.substr(j);\n                if(check(first, false) && check(second, true)) res2.push_back(first+"."+second);\n            }\n\t\t\t\n\t\t\t// Combine all the results\n            for(auto left:res1){\n                for(auto right:res2){\n                    res.push_back("(" + left + ", "+ right + ")");\n                }\n            }\n        }\n        return res;\n    }\n};\n```\n\n*Time Complexity* - `O(n^4)`  (Because `substr` function is `O(n)` worst case)\n*Space Compexity* - `O(n)`
['String', 'C++']