Ambiguous Coordinates || Backtracking || C# || Beats 94.44% ||
Rules to Consider.\n1. Has Two parts and each of these two parts contains at most 1 decimal\n2. Any non decimal part will not start with 0, if the part itsel is
# Rules to Consider.\n1. Has Two parts and each of these two parts contains at most 1 decimal\n2. Any non decimal part will not start with 0, if the part itsel isn\'t 0. (Example : (**005**, 4) is not allowed because 005 starts with 0, but (0, 4) is allowed)\n3. Decimal strings **can not end with a 0**, so **0.10, 0.0, 0.0000** these all are invalid.\n4. String like (**5.**, 7) , (**50.**, 9.8) are not valid.\n\n# Approach\nBreak the string into two string. Now handle the first part(or first axis or cordinate), take decimal in it and without decimal as well. In code flag=0 is handling the first axis of the coordinate. and flag=1 is handling the y axis or last part of the coordinate or last string.\n\nCheck code comment for handling the edge cases.\n\n# Code\n```\npublic class Solution {\n    IList<string> result= new List<string>();\n    public void AmbiguousCoordinatesHelper(string first, string last,bool firstHasDec, bool lasHasDec, int flag)\n    {\n       if (first == "" || last=="")\n        {\n            return;\n        }\n        if (flag >= 2)\n        {\n            if ((first[0]!=\'.\' && first[first.Length-1]!=\'.\') && (last[0] != \'.\' && last[last.Length - 1] != \'.\'))\n            {\n                result.Add("("+first+","+" "+last+")");\n            }\n            return;\n        }\n        if (flag == 0)\n        {\n            for(int i=0;i<first.Length; i++)\n            {\n                string temp = first;\n                if (i - 1 >= 0)\n                {\n                    first = first.Insert(i, ".");\n                    firstHasDec = true;\n                }\n                \n                if (first.Length > 1 && first[0] == \'0\' && first[1] != \'.\') /*To handle cases like 005, 004, 005.6 */\n                {\n                    first = temp;\n                    continue;\n                }\n                if (first.Length > 1 && first[0] == \'0\' && first[1] == \'.\') /*Handle test case like 0.0 or 0.0000*/\n                {\n                    decimal n = Convert.ToDecimal(first);\n                    if (n == 0)\n                    {\n                        first = temp;\n                        continue;\n                    }\n                    \n                }\n                if (firstHasDec && first[first.Length-1]!=\'.\' && first[first.Length - 1] == \'0\') /*Handle test case like 1.0, 1.5000, 4.020 (string is contained decimal to trigger this test case) */\n                {\n                    first = temp;\n                    continue;\n                }\n                AmbiguousCoordinatesHelper(first, last, firstHasDec, lasHasDec, flag + 1);\n                first = temp;\n                firstHasDec = false;\n            }\n        }\n        if (flag == 1)\n        {\n            for (int i = 0; i < last.Length; i++)\n            {\n                string temp = last;\n                if (i - 1 >= 0)\n                {\n                    last = last.Insert(i, ".");\n                    lasHasDec = true;\n                }\n            \n                if (last.Length > 1 && last[0] == \'0\' && last[1] != \'.\')\n                {\n                    last = temp;\n                    continue;\n                }\n                if (last.Length > 1 && last[0] == \'0\' && last[1] == \'.\')\n                {\n                    decimal n=Convert.ToDecimal(last);\n                    if (n == 0)\n                    {\n                        last = temp;\n                        continue;\n                    }\n                    \n                }\n                if (lasHasDec && last[last.Length - 1] != \'.\' && last[last.Length - 1] == \'0\')\n                {\n                    last = temp;\n                    continue;\n                }\n                AmbiguousCoordinatesHelper(first, last, firstHasDec, lasHasDec,flag + 1);\n                last = temp;\n                lasHasDec = false;\n            }\n        }\n    }\n    public IList<string> AmbiguousCoordinates(string s) {\n        s = s.Substring(1,s.Length-2);\n        for(int i = 0; i < s.Length; i++) \n        {\n            string left=s.Substring(0,i+1);\n            string right=s.Substring(i+1);\n            AmbiguousCoordinatesHelper(left, right,false,false, 0);\n        }\n        return result;\n    }\n}\n```
['C#']