C# - Runtime Error Message: Out of memory - Test Case 697 / 710
UPD: Problem solved\nThe most essential part was to distinguish even vs odd indices. Somehow having two sorted sorted sets based on parity is more efficient tha
**UPD**: Problem solved\nThe most essential part was to distinguish `even` vs `odd` indices. Somehow having two sorted sorted sets based on parity is more efficient than iterating one set and skip half of its elements...\n\nHello community.\n\nI have a solution in C#. It seems to be similar to accepted ones in other languages. But I can\'t get over my **Runtime Error: Out of memory** on **Test Case 697 / 710**\n\nI tried different optimizations but none of them helped to fix the memory issue.\n\nJava solutions suggested here use **TreeSet** class. I even had a similar solution with **SortedSet** which is an equivalent in C#.\nBut this solution fails with TLE. So I had to replace it with **List** with **BinarySearch** to overcome TLE.\n\nI tried to look for other C# solutions from the other contestants but I could not find a single one that uses C#.\n\nCan anyone sugggest what am I missing?\n\n```csharp\npublic class Solution\n{\n    public int[] MinReverseOperations(int n, int p, int[] banned, int k)\n    {\n        const int impossible = -1;\n        var ans = Enumerable.Repeat(impossible, n).ToArray();\n        var bannedSet = banned.ToHashSet();\n        var indicesToCheck = new List<int>();\n\n        for (var i = 0; i < n; i++)\n        {\n            if (bannedSet.Contains(i))\n            {\n                continue;\n            }\n\n            if (i == p)\n            {\n                continue;\n            }\n\n            indicesToCheck.Add(i);\n        }\n\n        var queue = new Queue<int>();\n        queue.Enqueue(p);\n        var step = 0;\n\n        while (queue.Count > 0)\n        {\n            var count = queue.Count;\n\n            for (var _ = 0; _ < count; _++)\n            {\n                var i = queue.Dequeue();\n\n                if (ans[i] != impossible)\n                {\n                    continue;\n                }\n\n                ans[i] = step;\n                indicesToCheck.Remove(i);\n\n                var low = Math.Abs(i - k + 1);\n                var high = new[] { i + k - 1, 2 * n - k - 1 - i, n - 1 }.Min();\n\n                if (low > high)\n                {\n                    continue;\n                }\n\n                var lowIndex = indicesToCheck.BinarySearch(low);\n\n                if (lowIndex < 0)\n                {\n                    lowIndex = ~lowIndex;\n                }\n\n                var highIndex = indicesToCheck.BinarySearch(high);\n\n                if (highIndex < 0)\n                {\n                    highIndex = ~highIndex - 1;\n                }\n\n                for (var index = lowIndex; index <= highIndex; index++)\n                {\n                    var j = indicesToCheck[index];\n\n                    if ((i + j + k + 1) % 2 != 0)\n                    {\n                        continue;\n                    }\n\n                    queue.Enqueue(j);\n                }\n            }\n\n            step++;\n        }\n\n        return ans;\n    }\n}\n```
['C#']