C# It is  hard level algorithm and I could not make it in the contest
Oct. 20, 2018\n927. Three Equal Parts\n\nIt is the third algorithm in weekly contest 107. I did come out the idea but my code had a few bugs in the contest. It 
Oct. 20, 2018\n927. Three Equal Parts\n\nIt is the third algorithm in weekly contest 107. I did come out the idea but my code had a few bugs in the contest. It took me more than 30 minutes in the contest and 20 minutes after the contest to make the code work. I also simplify the logic to make it readable. \n\nThe idea is to determine how many one in integer array. So first count how many one\'s in total using one iteration. And then it is true that number of 1 should be divisible by 3. And then the number without considing leading zero can be determined by the map of 1 with its index. \n\n1. Count how many 1 in the integer array, save each 1 and its index to a hashmap\n2. Determine the number in each part using binary string. \n3. Compare three numbers in three parts to make sure they are the same\n4. Considering leading zero, determine the two indexes to return. \n\nI made mistakes when I caculated a few numbers, one is ``` int index2 = map[number1];```, I could not determine second number\'s start index; one is to compare third number with first number and second number. Using string compare is to shorten the time to write my own comparison. ``` var digitsString = string.Join(string.Empty, digits); // look up stackoverflow.com```, I had to learn how to convert integer array to a string using C#. \n\nHere is my C# code to pass online judge after the contest. \n\n```\npublic class Solution {\n    public int[] ThreeEqualParts(int[] digits)\n        {\n            var notFound = new int[] { -1, -1 };\n\n            if (digits == null)\n                return notFound;\n\n            var countof1 = 0;\n            var length = digits.Length;\n            var map = new Dictionary<int, int>();\n            for (int i = 0; i < length; i++)\n            {\n                if (digits[i] == 1)\n                {\n                    map.Add(countof1, i);\n                    countof1++;\n                }\n            }\n\n            if (countof1 % 3 != 0)\n                return notFound;\n\n            if (countof1 == 0)\n                return new int[] { 0, 2 };\n\n            int number1 = countof1 / 3;\n\n            // narrow down the number without considering leading zero\n            int thirdNumberStart = map[countof1 - number1];\n\n            // constraint\n            int minimumLength = length - thirdNumberStart; // substring of number, there are some leading 0s maybe. \n\n            // compare the first number with third number            \n            int index1 = map[0];\n            int index2 = map[number1];\n            int index3 = map[countof1 - number1]; // test using countof1 = 3, 2 ; 6;\n\n            if (length - index1 + 1 < 3 * minimumLength)\n                return notFound;\n\n            var digitsString = string.Join(string.Empty, digits); // look up stackoverflow.com\n\n            var number = digitsString.Substring(thirdNumberStart);\n            var firstNumber = digitsString.Substring(index1, minimumLength);\n            var secondNumber = digitsString.Substring(index2, minimumLength);\n\n            var result = number.CompareTo(firstNumber) == 0 && number.CompareTo(secondNumber) == 0;\n            if (!result)\n            {\n                return notFound;\n            }\n            //               last digit of first number   third number\'s first digit\n            return new int[] { index1 + minimumLength - 1, index2 + minimumLength };\n    }\n}\n```\n
[]