C# Beats 100%
Intuition\nWhat an interesting challenge! I wonder why this task has such a low acceptance rate? (graph traversal)\n\n# Approach\nPain (bfs).\n\n# Complexity\n-
# Intuition\nWhat an interesting challenge! I wonder why this task has such a low acceptance rate? (graph traversal)\n\n# Approach\nPain (bfs).\n\n# Complexity\n- Time complexity: Nerve cells. o(n * log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: Tear Napkins. o(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution\n{\n    public int[] MinReverseOperations(int n, int p, int[] bannedVals, int K)\n    {\n        List<SortedSet<int>> remaining = new List<SortedSet<int>> { new SortedSet<int>(), new SortedSet<int>() };\n        HashSet<int> banned = new HashSet<int>(bannedVals);\n        for (int u = 0; u < n; u++)\n        {\n            if (u != p && !banned.Contains(u))\n            {\n                remaining[u & 1].Add(u);\n            }\n        }\n\n        Queue<int> queue = new Queue<int>();\n        queue.Enqueue(p);\n        int[] dist = new int[n];\n        Array.Fill(dist, -1);\n        dist[p] = 0;\n\n        while (queue.Count > 0)\n        {\n            int node = queue.Dequeue();\n            int lo = Math.Max(node - K + 1, 0);\n            lo = 2 * lo + K - 1 - node;\n            int hi = Math.Min(node + K - 1, n - 1) - (K - 1);\n            hi = 2 * hi + K - 1 - node;\n\n            List<int> toRemove = new List<int>();\n            foreach (int nei in remaining[lo % 2].GetViewBetween(lo, hi))\n            {\n                queue.Enqueue(nei);\n                dist[nei] = dist[node] + 1;\n                toRemove.Add(nei);\n            }\n\n            foreach (int nei in toRemove)\n            {\n                remaining[lo % 2].Remove(nei);\n            }\n        }\n\n        return dist;\n    }\n}\n\npublic static class SortedSetExtensions\n{\n    public static IEnumerable<T> GetViewBetween<T>(this SortedSet<T> set, T lowerValue, T upperValue) where T : IComparable<T>\n    {\n        if (set == null)\n            throw new ArgumentNullException(nameof(set));\n\n        return set.GetViewBetween(new Range<T>(lowerValue, upperValue));\n    }\n    \n    public static SortedSet<T> GetViewBetween<T>(this SortedSet<T> set, Range<T> range) where T : IComparable<T>\n    {\n        if (set == null)\n            throw new ArgumentNullException(nameof(set));\n\n        return set.GetViewBetween(range.LowerValue, range.UpperValue);\n    }\n}\n\npublic readonly struct Range<T> where T : IComparable<T>\n{\n    public T LowerValue { get; }\n    public T UpperValue { get; }\n\n    public Range(T lowerValue, T upperValue)\n    {\n        if (lowerValue.CompareTo(upperValue) > 0)\n            throw new ArgumentException("Lower value must be less than or equal to the upper value.");\n\n        LowerValue = lowerValue;\n        UpperValue = upperValue;\n    }\n}\n```
['C#']