C# - SortedSet - nlogn
Intuition\nUse SortedSet to overcome TimeLimitExceeded issue.\n\n# Approach\nChecking the existence in SortedSet is O(1) and doing search is a binary search ope
# Intuition\nUse SortedSet to overcome TimeLimitExceeded issue.\n\n# Approach\nChecking the existence in SortedSet is O(1) and doing search is a binary search operation since collection is sorted.\n\n# Complexity\n- Time complexity:\nO(n * log(n)) \n(n is count of arrival)\n\n- Space complexity:\nO(n)\n\n# Code\n```\npublic class Solution {\n\n    class DuplicateKeyComparer : IComparer<int>\n    {\n        public int Compare(int x, int y)\n        {\n            int result = x.CompareTo(y);\n\n            result = result == 0 ? 1 : result;\n\n            return result;\n        }            \n    }\n\n    class ServerEqualityComparer : IComparer<Server>\n    {\n        public int Compare(Server x, Server y)\n        {\n            if (x == null || y == null) return -1;\n\n            return x.Id.CompareTo(y.Id);\n        }\n\n        public bool Equals(Server x, Server y)\n        {\n            if(x == null || y == null) return false;\n\n            return x.Id.Equals(y.Id);\n        }\n\n        public int GetHashCode(Server obj)\n        {\n            return obj.Id.GetHashCode();\n        }\n    }\n\n    class Server\n    {\n        public int Id { get; set; }\n\n        public int ReqCount { get; set; }\n\n        public int FreeTime { get; set;}\n    }\n\n    public IList<int> BusiestServers(int k, int[] arrival, int[] load) {\n        var busyServers = new SortedList<int, Server>(new DuplicateKeyComparer()); // free time, server\n        var serverRange = Enumerable.Range(0, k);\n        var serverReqCount = new Dictionary<int, int>(serverRange.Select(i => new KeyValuePair<int, int>(i, 0))); // server, req count\n        var freeServers = new SortedSet<Server>(serverRange.Select(i => new Server\n        {\n            FreeTime = 0,\n            Id = i,\n            ReqCount = 0\n        }), new ServerEqualityComparer());\n\n        for (var i = 0; i < arrival.Length; i++)\n        {\n            while (busyServers.Count > 0 && busyServers.ElementAt(0).Value.FreeTime <= arrival[i])\n            {\n                var firstServer = busyServers.First().Value;\n                freeServers.Add(firstServer);\n                busyServers.RemoveAt(0);\n            }\n\n            if (freeServers.Count == 0)\n            {\n                //req dropped\n                continue;\n            }\n\n            Server freeServer = null;\n\n            if (freeServers.Contains(new Server { Id = i % k }))\n            {\n                freeServers.TryGetValue(new Server { Id = i % k }, out freeServer);\n            }\n            else\n            {\n                //first or default will do binary search if the collection is sorted\n                freeServer = freeServers.FirstOrDefault(j => j.Id > (i % k)) ?? freeServers.Min;                    \n            }\n\n            serverReqCount[freeServer.Id]++;\n            freeServer.FreeTime = arrival[i] + load[i];\n            busyServers.Add(freeServer.FreeTime, freeServer);\n            freeServers.Remove(freeServer);\n        }\n\n        var maxReqCount = 0;\n        var maxReqServers = new List<int>(serverReqCount.Count);\n\n        foreach (var item in serverReqCount)\n        {\n            if (item.Value > maxReqCount)\n            {\n                maxReqCount = item.Value;\n                maxReqServers = new List<int> { item.Key };\n            }\n            else if (item.Value == maxReqCount)\n            {\n                maxReqServers.Add(item.Key);\n            }\n        }\n\n        return maxReqServers;\n    }\n}\n```
['Ordered Map', 'Ordered Set', 'C#']